偶尔二进制XML文件行#XX:错误充气类<&不明GT; [英] Occasional Binary XML file line #XX: Error inflating class <unknown>

查看:188
本文介绍了偶尔二进制XML文件行#XX:错误充气类<&不明GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要活动,持有主菜单。此菜单有一个选项来启动第二个活动,这是一个 SurfaceView 后裔。

我得到这个错误几次,但并非总是如此。我需要执行调用通过的第一个活动的菜单按钮的第二个活动,然后返回到第一个活动的过程。最终(通常在7日重复),错误发生的第二次时。活动正在展开。 Whitout调试器,手机屏幕将变为黑色,被阻止约30秒或更长时间,然后我看到对话框将其关闭。在调试器,应用程序将停止在这个异常。

第二次活动我的布局文件是:

 <?XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>    < com.myapp.MySecActivity
      机器人:layout_width =FILL_PARENT
      机器人:layout_height =FILL_PARENT机器人:ID =@ + ID / sec_view/>< /&的FrameLayout GT;

我有一个类 MySecActivity 时,负载上构造此布局。

我想通了,我在的setContentView 得到一个 InflateException 。我检查了我的ID传递给的setContentView 键,它是相同的,不为空,在所有条件:

  INT ID = getResources()则getIdentifier(mylayout,布局,getPackageName());如果(ID&下; = 0){
    ID = 0; //只是为了调试
}其他{
   尝试{
       的setContentView(ID);
    }赶上(InflateException E){
       错误= TRUE;
    }
}


解决方案

您需要有< XML ..> prelude以及如设置你的XML命名空间。你在干什么呢?

 <?XML版本=1.0编码=UTF-8&GT?;
< com.myapp.MySecActivity
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    ...

如果 com.myapp.MySecActivity 不是你的根元素,然后尝试粘贴您的整个布局如果您希望我们来关注一下吧。

I have a main activity, that holds the main menu. This menu has an option to start a second activity, which is a SurfaceView descendent.

I'm getting this error several times, but not always. I need to perform the process of calling the second activity via the first activity's menu button, and then returning to the first activity. Eventually (Usually on the 7th repetition), the error happens when the 2nd. activity is being launched. Whitout the debugger, the phone screen becomes black and is blocked for about 30 or more seconds, then I see the dialog to close it. In debugger, the app stops on this exception.

My layout file for the second activity is:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <com.myapp.MySecActivity
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" android:id="@+id/sec_view"/>

</FrameLayout>

I have a Class MySecActivity, with loads this layout on constructor.

I figured out that I'm getting an InflateException on setContentView. I'm checking the id I pass to setContentView and it's the same, not null, on all conditions:

int id = getResources().getIdentifier("mylayout", "layout", getPackageName());

if (id<= 0) {
    id= 0;  // just for debugging
} else {
   try {
       setContentView(id);
    } catch (InflateException e) {
       error = true;
    }
}

解决方案

You need to have the <?xml .. ?> prelude as well as set your xml namespace. Are you doing this?

<?xml version="1.0" encoding="utf-8"?>
<com.myapp.MySecActivity
    xmlns:android="http://schemas.android.com/apk/res/android"
    ...

If com.myapp.MySecActivity is not your root element, then try pasting your entire layout if you'd us to look at it.

这篇关于偶尔二进制XML文件行#XX:错误充气类&LT;&不明GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆