偶尔出现二进制 XML 文件行 #XX:错误膨胀类
我有一个主要活动,包含主菜单。此菜单有一个启动第二个活动的选项,该活动是 SurfaceView 的后代。
我多次收到此错误,但并非总是如此。我需要执行通过第一个活动的菜单按钮调用第二个活动的过程,然后返回到第一个活动。最终(通常在第七次重复时),错误发生在第二次时。活动正在开展中。如果没有调试器,手机屏幕会变黑并被阻塞大约 30 秒或更长时间,然后我看到关闭它的对话框。在调试器中,应用程序会因此异常而停止。
我的第二个活动的布局文件是:
<?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>
我有一个类 MySecActivity
,并在构造函数上加载此布局。
我发现我在 setContentView
上遇到了 InflateException
。我正在检查传递给 setContentView
的 id,它在所有条件下都是相同的,而不是 null:
int id = getResources().getIdentifier("mylayout", "layout", getPackageName());
if (id<= 0) {
id= 0; // just for debugging
} else {
try {
setContentView(id);
} catch (InflateException e) {
error = true;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要有
前奏以及设置 xml 命名空间。你在做这个吗?
如果 com.myapp.MySecActivity 不是您的根元素,请尝试粘贴整个布局(如果您希望我们查看)。
You need to have the
<?xml .. ?>
prelude as well as set your xml namespace. Are you doing this?If
com.myapp.MySecActivity
is not your root element, then try pasting your entire layout if you'd us to look at it.