-1

I have created a simple UI divided in two parts :

  • An hard coded fragment that contains a navigation menu that is always visible

  • A frame layout which i am using as a container where i replace a fragment to display a content based on what entry is selected in the navigation menu

My problem is that it crashes when i'm inflating layouts. I have tried to use both the normal fragment API and the fragment support API (+ a library for the preference fragment) but it crashes in both cases.

Here is the call stack :

03-06 09:46:15.551: W/System.err(26183): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
03-06 09:46:15.565: W/System.err(26183):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-06 09:46:15.571: W/System.err(26183):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-06 09:46:15.578: W/System.err(26183):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-06 09:46:15.581: W/System.err(26183):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-06 09:46:15.588: W/System.err(26183):    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-06 09:46:15.595: W/System.err(26183):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-06 09:46:15.601: W/System.err(26183):    at ubone.telnetui.fragments.PanelFragment.onCreateView(PanelFragment.java:40)
03-06 09:46:15.605: W/System.err(26183):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
03-06 09:46:15.615: W/System.err(26183):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:915)
03-06 09:46:15.618: W/System.err(26183):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1099)
03-06 09:46:15.628: W/System.err(26183):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1201)
03-06 09:46:15.631: W/System.err(26183):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:292)
03-06 09:46:15.638: W/System.err(26183):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
03-06 09:46:15.641: W/System.err(26183):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-06 09:46:15.651: W/System.err(26183):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-06 09:46:15.655: W/System.err(26183):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-06 09:46:15.665: W/System.err(26183):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-06 09:46:15.668: W/System.err(26183):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272)
03-06 09:46:15.678: W/System.err(26183):    at android.app.Activity.setContentView(Activity.java:1887)
03-06 09:46:15.685: W/System.err(26183):    at ubone.telnetui.TelnetActivity.onCreate(TelnetActivity.java:33)
03-06 09:46:15.688: W/System.err(26183):    at android.app.Activity.performCreate(Activity.java:5031)
03-06 09:46:15.691: W/System.err(26183):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
03-06 09:46:15.698: W/System.err(26183):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2038)
03-06 09:46:15.701: W/System.err(26183):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2099)
03-06 09:46:15.705: W/System.err(26183):    at android.app.ActivityThread.access$600(ActivityThread.java:134)
03-06 09:46:15.708: W/System.err(26183):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
03-06 09:46:15.711: W/System.err(26183):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 09:46:15.715: W/System.err(26183):    at android.os.Looper.loop(Looper.java:137)
03-06 09:46:15.718: W/System.err(26183):    at android.app.ActivityThread.main(ActivityThread.java:4797)
03-06 09:46:15.721: W/System.err(26183):    at java.lang.reflect.Method.invokeNative(Native Method)
03-06 09:46:15.725: W/System.err(26183):    at java.lang.reflect.Method.invoke(Method.java:511)
03-06 09:46:15.728: W/System.err(26183):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:776)
03-06 09:46:15.735: W/System.err(26183):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:543)
03-06 09:46:15.738: W/System.err(26183):    at dalvik.system.NativeStart.main(Native Method)
03-06 09:46:15.738: W/System.err(26183): Caused by: java.lang.reflect.InvocationTargetException
03-06 09:46:15.755: W/System.err(26183):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-06 09:46:15.755: W/System.err(26183):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-06 09:46:15.758: W/System.err(26183):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-06 09:46:15.758: W/System.err(26183):    ... 33 more
03-06 09:46:15.758: W/System.err(26183): Caused by: java.lang.NullPointerException
03-06 09:46:15.765: W/System.err(26183):    at android.content.res.ResourcesEx.getThemeDrawable(ResourcesEx.java:516)
03-06 09:46:15.765: W/System.err(26183):    at android.content.res.ResourcesEx.loadDrawable(ResourcesEx.java:491)
03-06 09:46:15.765: W/System.err(26183):    at android.content.res.TypedArray.getDrawable(TypedArray.java:606)
03-06 09:46:15.768: W/System.err(26183):    at android.view.View.<init>(View.java:3352)
03-06 09:46:15.768: W/System.err(26183):    at android.view.ViewGroup.<init>(ViewGroup.java:427)
03-06 09:46:15.768: W/System.err(26183):    at android.widget.LinearLayout.<init>(LinearLayout.java:176)
03-06 09:46:15.771: W/System.err(26183):    at android.widget.LinearLayout.<init>(LinearLayout.java:172)
03-06 09:46:15.771: W/System.err(26183):    ... 36 more

XML :

UI divided in two parts :

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="ubone.telnetui.TelnetActivity" >

    <fragment
        android:id="@+id/panel_fragment"
        android:name="ubone.telnetui.fragments.PanelFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="0sp"
        android:paddingLeft="0sp"
        android:paddingRight="0sp"
        android:paddingTop="0sp"
        tools:layout="@layout/panel_fragment" />

    <FrameLayout
        android:id="@+id/content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Navigation menu fragment :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@style/AppTheme"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/LinearLayout3"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@style/AppTheme"
        android:orientation="vertical"
        android:paddingBottom="2dp"
        android:paddingLeft="2dp"
        android:paddingRight="2dp"
        android:paddingTop="2dp" >

        <ImageView
            android:id="@+id/imageViewSessions"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@style/AppTheme"
            android:contentDescription="@string/action_select_all"
            android:src="@drawable/ic_action_select_all" />

        <ImageView
            android:id="@+id/imageViewSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@style/AppTheme"
            android:contentDescription="@string/action_settings"
            android:src="@drawable/ic_action_settings" />

        <ImageView
            android:id="@+id/imageViewHelp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@style/AppTheme"
            android:contentDescription="@string/action_help"
            android:src="@drawable/ic_action_help" />

    </LinearLayout>

</LinearLayout>

Content fragment 1

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/settings_fragment" >
    <EditTextPreference android:dialogMessage="DialogMessage" android:dialogTitle="DialogTitle"/>
    <SwitchPreference android:summaryOn="Activate or deactivate the Bluetooth" android:summaryOff="Activate or deactivate the Bluetooth" android:switchTextOff="off" android:switchTextOn="on" android:title="Bluetooth"/>
</PreferenceScreen>

Content fragment 2 :

<ubone.telnetui.views.TnScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tn_screen_fragment"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="3dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="3dp"
    android:background="@android:color/transparent" >
</ubone.telnetui.views.TnScreen>

Java where the exception is thrown :

@Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState )
{
    final ListView lv = (ListView) inflater.inflate( R.layout.panel_fragment, container, false );
    lv.setOnItemClickListener( this );
    return lv;
}

Any idea ? Thank you.

Virus721
  • 8,061
  • 12
  • 67
  • 123
  • Which of the listed file is `R.layout.panel_fragment` referring to ? – P-a Bäckström Mar 06 '15 at 12:08
  • seems to be problem in initializing view `at android.view.View.(View.java:3352)` where is the listview in any of you layouts? – Raghunandan Mar 06 '15 at 12:09
  • @P-aBäckström It's the second XML code. – Virus721 Mar 06 '15 at 12:09
  • @Raghunandan I just realized there is a mistake in my Java code : it's not a list view, it's a LinearLayout. but this is not what's causing the problem anyway because the exception is thrown before the cast. – Virus721 Mar 06 '15 at 12:15
  • possible duplicate of [Android - Error inflating class](http://stackoverflow.com/questions/28896418/android-error-inflating-class) – AADProgramming Mar 06 '15 at 13:04
  • It's not a "possible duplicate", it IS a duplicate. Since all i got there was a down vote and a close vote from a frustrated nerd but not a single constructive comment at all, i decided to post it at another moment so that other people would see it. But that helps a lot, thanks... – Virus721 Mar 06 '15 at 13:12
  • possible duplicate of [Android: Error inflating class](http://stackoverflow.com/questions/3739661/android-error-inflating-class) – 2Dee Mar 09 '15 at 10:03

1 Answers1

1

I think backgrounds for your imageviews (android:background="@style/AppTheme") are not correct. You can not set styles as background. It seems for some reason android build environment does not detect this.

Okas
  • 2,664
  • 1
  • 19
  • 26
  • Thanks for your help, but this is not the source of the problem unfortunately. By commenting out some things here and there ive found that it fails even if the LinearLayout of the navigation menu is empty. The fragment declared in the main XML layout and which is supposed to contain the menu is what is causing the crash. I tried loading a different fragment in that place instead of the navigation menu, and it did work, so the problem probably comes from this navigation menu. – Virus721 Mar 06 '15 at 14:13
  • did you also remove android:background="@style/AppTheme" when you set navigation menu LinearLayout to empty? – Okas Mar 06 '15 at 14:16
  • Yes you were right. I have removed all the background attributes and now it works. I don't remeber if this is auto generated code or if i pasted that from a tutorial, but seems like it was the source of the problem. Thanks for the help. – Virus721 Mar 06 '15 at 14:18