问题
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;
}
}
回答1:
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.
来源:https://stackoverflow.com/questions/5231865/occasional-binary-xml-file-line-xx-error-inflating-class-unknown