Question

My App uses ActionBar tabs with Fragments and as a first step I used only the v4 library. but now I implemented the v7 appcompat as well. and on devices with API>11 it worked fine, Because I just use ActivityCompat.invalidateOptionsMenu(this.getActivity()); but with devices with API<11 the App seemed to crash every time getActivity().supportInvalidateOptionsMenu(); gets called saying there is an inflate exception : android.view.InflateException: Binary XML file line #85: Error inflating class and in the dalvikvm : Could not find class 'android.support.v7.widget.SearchView$5', referenced from method android.support.v7.widget.SearchView.addOnLayoutChangeListenerToDropDownAnchorSDK11.

I searched online for the last 3 weeks and here is stuff I managed to find:

first there is this.

which wasn't really enough to solve the problem but then I also found this.

Now I use eclipse but after reading Issue 67388 from the link above I downloaded android studio 0.5.4 in order to see if it will work for me as well. I needed to set the Build gradle to version 0.9.0 and the android.support.v4/android.support.v7 to version 19.0.1 because with 19.1.0 the App still crashes.

now the app runs okay on devices API>11 like android 2.2.3 2.3 etc but will crash if you rotate the device from NullPointerException

the code that causes the exception according to the logcat is :

mSearchView = new MySearchView(getActivity());

on 4.4 works fine, but when I run the App on android 3.0 or 4.0/4.1/4.2.1 etc the App crashes again with android.view.InflateException: Binary XML file line #85: Error inflating class and will crash when I rotate the device.

is there anyway I could solve this problem?how? I am really stuck and don't know what to do any more Thanks in advance.

here is the full log cat:

InflateException

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    android.view.InflateException: Binary XML file line #85: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:513)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
            at android.support.v7.widget.SearchView.<init>(SearchView.java:262)
            at android.support.v7.widget.SearchView.<init>(SearchView.java:254)
            at com.samer.deutschwordbookapp.Words$MySearchView.<init>(Words.java:459)
            at com.samer.deutschwordbookapp.Words.onCreateOptionsMenu(Words.java:94)
            at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
            at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
            at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
            at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:617)
            at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
            at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
            at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
            at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)
            at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1998)
            at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:481)
            at android.support.v7.app.ActionBarActivity.superOnPreparePanel(ActionBarActivity.java:236)
            at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:644)
            at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
            at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
            at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
            at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)
            at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1998)
            at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:481)
            at android.support.v7.app.ActionBarActivity.superOnPreparePanel(ActionBarActivity.java:236)
            at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:644)
            at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
            at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
            at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
            at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)
            at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1998)
            at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:481)
            at android.support.v7.app.ActionBarActivity.superOnPreparePanel(ActionBarActivity.java:236)
            at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:644)
            at android.support.v7.app.ActionBarActivityDelegateBase.supportInvalidateOptionsMenu(ActionBarActivityDelegateBase.java:421)
            at android.support.v7.app.ActionBarActivity.supportInvalidateOptionsMenu(ActionBarActivity.java:172)
            at com.samer.deutschwordbookapp.Words.onPrepareOptionsMenu(Words.java:117)
            at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1596)

NullPointerException

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NullPointerException
            at android.view.ViewConfiguration.get(ViewConfiguration.java:211)
            at android.view.View.<init>(View.java:1814)
            at android.view.View.<init>(View.java:1856)
            at android.view.View.<init>(View.java:1834)
            at android.view.ViewGroup.<init>(ViewGroup.java:285)
            at android.widget.LinearLayout.<init>(LinearLayout.java:115)
            at android.support.v7.widget.SearchView.<init>(SearchView.java:258)
            at android.support.v7.widget.SearchView.<init>(SearchView.java:254)
            at com.samer.deutschwordbookapp.Expressions$MySearchView.<init>(Expressions.java:432)
            at com.samer.deutschwordbookapp.Expressions.onCreateOptionsMenu(Expressions.java:89)
            at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
            at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1956)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
            at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:232)
            at android.support.v7.app.ActionBarActivityDelegateBase$1.run(ActionBarActivityDelegateBase.java:70)
            at android.os.Handler.handleCallback(Handler.java:587)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:123)
            at android.app.ActivityThread.main(ActivityThread.java:4627)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:521)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
            at dalvik.system.NativeStart.main(Native Method)
Was it helpful?

Solution

I ended up solving it with a workaround but forgot to post the answer.

The problem was caused due to the fragments manipulating the nav bar to display different possible actions for the different fragments, and sometimes, when navigating between the fragments, the app would crash with the above described error on the above described devices, in essence this should work, but again, it's a really weird android bug that I didn't fully understand. So Implemented an interface on the activity level that had the nav bar and added the interface in the fragments, then each fragment simply asked the activity to change the actions based on it's needs, which prevented the crash and worked as it should

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top