我正在使用ongakuer/CircleIndicator库来添加viewpager指标。我已经使用了示例代码,只是将customViewpager.addOnPageChangeListener
从customViewpager.setOnPageChangeListener
更改为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)
,因为它显示编译错误。之后没有编译错误。
当我运行活动时,我会直接得到以下错误:
import java.util.Random;
import java.util.Scanner;
public class NewClass {
public static void main(String[] args) {
char[] letters = generateLetters();
String input = getWord();
String[] words = input.split(" ");
if (words.length == letters.length) {
if (check(letters, words)) {
System.out.println("Yeah");
} else {
System.out.println("Oops");
}
} else {
System.out.println("INVALID");
}
}
public static Boolean check(char[] letters, String[] words) {
for (int i = 0; i < letters.length; i++) {
if (words[i].charAt(0) != letters[i]) {
return false;
}
}
return true;
}
public static String getWord() {
System.out.println("Enter a word for your letters: ");
Scanner wordInput = new Scanner(System.in);
String inputWord = wordInput.nextLine().toUpperCase();
return inputWord;
}
public static char[] generateLetters() {
Random randomLetter = new Random();
char[] letters = new char[3];//Make it varaible length
for (int i = 0; i < letters.length; i++) {
letters[i] = (char) ((int) randomLetter.nextInt(26) + 'A');
System.out.printf(letters[i] + " ");
}
return letters;
}
}
答案 0 :(得分:7)
java.lang.NoSuchMethodError: No virtual method setAdapterCount ...
使缓存无效,然后重新启动Android Studio解决了我的错误。 You can find directions to invalidate caches in IntelliJ (the software Android Studio is built upon) at this link
答案 1 :(得分:3)
我有同样的问题,在我的情况下,解决方案如下:
答案 2 :(得分:0)
当我使用与我的其他支持库不兼容的 support-v4 库版本时出现此错误:
compile ('com.android.support:support-v4:22.1.1') {
// Force stable version of support-v4
force = true
}
不幸的是,我找到的唯一解决方案是从我的构建中删除 support-v4 库。