当我在我的Android项目上工作时,我发现Logcat很烦人(没有将滚动条保持在给定点)并且读到更新SDK版本添加了一个暂停按钮来解决这个问题。我更新到SDK版本17,现在我遇到了一些我之前没有的奇怪问题。我删除并添加了android支持库,但没有运气。我一直在阅读互联网,但我仍然无法弄明白。日志在下面。
03-22 15:54:18.558: E/AndroidRuntime(11597): FATAL EXCEPTION: main
03-22 15:54:18.558: E/AndroidRuntime(11597): java.lang.RuntimeException: Unable to start activity ComponentInfo{kris.android/kris.android.ActivityPortfolio}: android.view.InflateException: Binary XML file line #184: Error inflating class android.support.v4.view.ViewPager
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.os.Looper.loop(Looper.java:150)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.ActivityThread.main(ActivityThread.java:4263)
03-22 15:54:18.558: E/AndroidRuntime(11597): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 15:54:18.558: E/AndroidRuntime(11597): at java.lang.reflect.Method.invoke(Method.java:507)
03-22 15:54:18.558: E/AndroidRuntime(11597): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-22 15:54:18.558: E/AndroidRuntime(11597): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-22 15:54:18.558: E/AndroidRuntime(11597): at dalvik.system.NativeStart.main(Native Method)
03-22 15:54:18.558: E/AndroidRuntime(11597): Caused by: android.view.InflateException: Binary XML file line #184: Error inflating class android.support.v4.view.ViewPager
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-22 15:54:18.558: E/AndroidRuntime(11597): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:231)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.Activity.setContentView(Activity.java:1742)
03-22 15:54:18.558: E/AndroidRuntime(11597): at kris.android.ActivityPortfolio.onCreate(ActivityPortfolio.java:44)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
03-22 15:54:18.558: E/AndroidRuntime(11597): ... 11 more
03-22 15:54:18.558: E/AndroidRuntime(11597): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loader dalvik.system.PathClassLoader[/data/app/kris.android-2.apk]
03-22 15:54:18.558: E/AndroidRuntime(11597): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-22 15:54:18.558: E/AndroidRuntime(11597): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-22 15:54:18.558: E/AndroidRuntime(11597): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
03-22 15:54:18.558: E/AndroidRuntime(11597): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
03-22 15:54:18.558: E/AndroidRuntime(11597): ... 21 more
答案 0 :(得分:92)
转到Project
- > Properties
- > Java Build Path
,然后选择Order and export
标签。
设置android-support-v4.jar库并将其放入列表顶部。
然后清理并重建项目。
答案 1 :(得分:0)
03-22 15:54:18.558: E/AndroidRuntime(11597): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loader dalvik.system.PathClassLoader[/data/app/kris.android-2.apk]
我尝试按照上面的链接移动JAR,但它对我不起作用。什么工作是@弗拉基米尔的回答。
如果检查项目的.classpath(在SDK.r17之前生成),您将看到它不包含android-support-v4.jar
的classpathentry。从SDK.r17开始,这似乎是一个强制性条目,因此@ Vladimir的回答是正确的。
谷歌试图(不充分)解释this。