我正在尝试在我的一个项目中使用Realm Adapter。但是我无法使用它。
我何时将compile 'io.realm:android-adapters:1.0.1'
添加到gradle文件中。项目编译成功,但应用程序崩溃tabLayout.setupWithViewPager(viewPager);
- 我将viewpager添加到tabLayout的行。
当我评论compile 'io.realm:android-adapters:1.0.1'
我附上了活动的屏幕截图。它在第57行崩溃。我还粘贴了错误的堆栈跟踪
05-09 22:11:48.074 16932-16932/com.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app, PID: 16932
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/TintManager;
at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1185)
at android.support.design.widget.TabLayout.createTabView(TabLayout.java:656)
at android.support.design.widget.TabLayout.addTabView(TabLayout.java:695)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:386)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:361)
at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645)
at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616)
at com.app.MainActivity.onCreate(MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.TintManager" on path: DexPathList[[zip file "/data/app/com.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app-1/lib/arm64, /data/app/com.app-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.design.widget.TabLayout$TabView.<init>(TabLayout.java:1185)
at android.support.design.widget.TabLayout.createTabView(TabLayout.java:656)
at android.support.design.widget.TabLayout.addTabView(TabLayout.java:695)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:386)
at android.support.design.widget.TabLayout.addTab(TabLayout.java:361)
at android.support.design.widget.TabLayout.setTabsFromPagerAdapter(TabLayout.java:645)
at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:616)
at com.app.MainActivity.onCreate(MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: android.support.v7.widget.TintManager
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 21 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
以下是应用程序中build.gradle文件的片段 -
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.github.paolorotolo:appintro:3.2.0'
compile 'io.realm:android-adapters:1.0.1'
}
答案 0 :(得分:1)
所有支持库必须具有相同的版本。 23.1.0或23.1.1或任何其他但你不能使用不同的版本。
尝试对所有库使用23.3.0
。
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.github.paolorotolo:appintro:3.2.0'
compile 'io.realm:android-adapters:1.0.1'
答案 1 :(得分:1)
io.realm:android-adapters:1.0.1
需要appcompat-v7
版本23.3.0或更高版本。
顺便说一句,我建议使用变量作为支持版本。 (所有支持库都应该相同。)
def supportVersion = '23.3.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "com.android.support:appcompat-v7:$supportVersion"
compile "com.android.support:design:$supportVersion"
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile "com.android.support:cardview-v7:$supportVersion"
compile 'com.github.paolorotolo:appintro:3.2.0'
compile 'io.realm:android-adapters:1.0.1'