Vishal
Vishal

Reputation: 467

NoSuchMethodError: No virtual method removeOnPageChangeListener

I am using ongakuer/CircleIndicator library to add viewpager indicators. I have used the sample code as it is except changing a small code from customViewpager.addOnPageChangeListenerto customViewpager.setOnPageChangeListenerbecause it was showing compile error. After that there was no compile error.

When I run the activity, I straightaway get the following error:

java.lang.NoSuchMethodError: No virtual method removeOnPageChangeListener(Landroid/support/v4/view/ViewPager$OnPageChangeListener;)V in class Landroid/support/v4/view/ViewPager; or its super classes (declaration of 'android.support.v4.view.ViewPager' appears in /data/app/com.app.app-2/base.apk)
            at me.relex.circleindicator.CircleIndicator.setViewPager(CircleIndicator.java:127)
            at com.app.app.ViewpagerActivity.onCreate(ViewpagerActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Upvotes: 16

Views: 28241

Answers (3)

Darshan Dorai
Darshan Dorai

Reputation: 659

Faced a similar issue with RecyclerView.Adapter -

java.lang.NoSuchMethodError: No virtual method setAdapterCount ...

Invalidating caches and then restarting Android Studio resolved the error in my case. You can find directions to invalidate caches in IntelliJ (the software Android Studio is built upon) at this link.

Upvotes: 9

xemacobra
xemacobra

Reputation: 1954

I had the same issue and in my case the solution was as follows:

Solution:

  • Go to the SDK Manager.
  • Go to the SDK Tools tab.
  • Make sure you install the latest version of Android Support Library, rev 22.
  • Now try running your app again.

Explanation:

  • removeOnPageChangeListener was only added in Revision 22 of the support-v4 library.
  • For some reason, Android Studio will not let you know that you don't have the full revision downloaded and installed.

Upvotes: 4

IgorGanapolsky
IgorGanapolsky

Reputation: 26821

I had this error when I used a version of support-v4 library which wasn't compatible with my other support libraries:

compile ('com.android.support:support-v4:22.1.1') {
    // Force stable version of support-v4
    force = true
}

Unfortunately, the only solution I found is by removing support-v4 library from my build altogether.

Upvotes: 0

Related Questions