mlidal mlidal - 22 days ago 15
Android Question

Crash on Android 2.3.3 after upgrading to support library 25.0.0 (java.lang.NoSuchMethodError: android.view.View.isAttachedToWindow)

After upgrading to the latest version of the support library, I'm no longer able to run the app on Android 2.3.3. The app crashes during startup with the


11-01 13:53:16.580 2115-2115/no.bouvet.routeplanner.atb E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoSuchMethodError: android.view.View.isAttachedToWindow
at android.support.v7.widget.ForwardingListener$2.(ForwardingListener.java:102)
at android.support.v7.widget.ForwardingListener.addDetachListenerBase(ForwardingListener.java:101)
at android.support.v7.widget.ForwardingListener.(ForwardingListener.java:78)
at android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton$1.(ActionMenuPresenter.java:650)
at android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton.(ActionMenuPresenter.java:650)
at android.support.v7.widget.ActionMenuPresenter.initForMenu(ActionMenuPresenter.java:114)
at android.support.v7.view.menu.MenuBuilder.addMenuPresenter(MenuBuilder.java:262)
at android.support.v7.widget.ActionMenuView.getMenu(ActionMenuView.java:656)
at android.support.v7.widget.Toolbar.ensureMenu(Toolbar.java:1037)
at android.support.v7.widget.Toolbar.getMenu(Toolbar.java:1008)
at android.support.v7.widget.ToolbarWidgetWrapper.getMenu(ToolbarWidgetWrapper.java:676)
at android.support.v7.app.ToolbarActionBar.getMenu(ToolbarActionBar.java:595)
at android.support.v7.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:447)
at android.support.v7.app.ToolbarActionBar$1.run(ToolbarActionBar.java:61)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)


The dependencies used are:

compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:support-compat:25.0.0'
compile 'com.android.support:support-core-ui:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:preference-v7:24.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services-maps:9.6.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.maps.android:android-maps-utils:0.4'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:recyclerview-v7:24.2.1'


The error disappears of I downgrade to 24.2.2, but this causes other problems (when using the default android searchview, the text that the user enters is not visible, even though the autocomplete works fine)

I assume this is a bug in the support library. Have anyone seen the same problem and know of a fix?

Answer

It's an issue with Support Library 25.0.0:https://code.google.com/p/android/issues/detail?id=225647. You can reproduce the issue by creating a new project and using the standard Basic Activity template in Android Studio. The app will crash on setSupportActionBar(toolbar); on devices API 11 and below. I didn't find another solution except to downgrade support library version.