Random binary line of XML file #XX: error inflating class <unknown>

I have a main action that contains a main menu. This menu has the ability to trigger a second action, which is a descendant of SurfaceView .

I get this error several times, but not always. I need to complete the process of invoking the second action using the button of the first action, and then return to the first action. In the end (usually at the 7th repetition), an error occurs when the second. activity begins. In the debugger, the phone screen turns black and locks up for about 30 seconds or more, after which I see a dialog to close it. In the debugger, the application dwells on this exception.

My layout file for the second action:

 <?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 MySecActivity class that loads this layout into the constructor.

I realized that I InflateException getting an InflateException on setContentView . I check the identifier that I pass to setContentView , and the same, but not null, under 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; } } 
+4
source share
1 answer

You need to have a prelude <?xml .. ?> And also set the xml namespace. You do it?

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

If com.myapp.MySecActivity not your root element, try pasting the entire layout if you want to see it.

+3
source

Source: https://habr.com/ru/post/1342800/


All Articles