Android ViewPager错误

时间:2012-04-13 16:55:38

标签: android android-viewpager

我正在使用Android支持包v4中的ViewPager,但它说它无法在支持包中找到ViewPager类。而且我不知道如何解决它?

logcat的

04-13 16:48:05.842: E/AndroidRuntime(1211): FATAL EXCEPTION: main
04-13 16:48:05.842: E/AndroidRuntime(1211): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alpha.liveshitplus/com.alpha.liveshitplus.Discography}: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.v4.view.ViewPager
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.os.Looper.loop(Looper.java:137)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.ActivityThread.main(ActivityThread.java:4340)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invokeNative(Native Method)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at java.lang.reflect.Method.invoke(Method.java:511)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at dalvik.system.NativeStart.main(Native Method)
04-13 16:48:05.842: E/AndroidRuntime(1211): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class android.support.v4.view.ViewPager
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.Activity.setContentView(Activity.java:1835)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at com.alpha.liveshitplus.Discography.onCreate(Discography.java:17)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.Activity.performCreate(Activity.java:4465)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
04-13 16:48:05.842: E/AndroidRuntime(1211):     ... 11 more
04-13 16:48:05.842: E/AndroidRuntime(1211): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager
04-13 16:48:05.842: E/AndroidRuntime(1211):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.view.LayoutInflater.createView(LayoutInflater.java:552)
04-13 16:48:05.842: E/AndroidRuntime(1211):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-13 16:48:05.842: E/AndroidRuntime(1211):     ... 21 more

3 个答案:

答案 0 :(得分:7)

可能是android-support-v4.jar的版本不对。 溶液:

  1. 关闭日食
  2. 删除项目的libs文件夹中的android-support-v4.jar
  3. 重新开启日食
  4. 右键单击项目,Android工具 - >添加支持库...然后eclipse将为您的项目下载正确版本的android-support-v4.jar并将其添加到您的项目中。
  5. 重建并运行你的项目,它会好的!

答案 1 :(得分:0)

确保将兼容性jar文件复制到项目的libs文件夹中,并将其添加到构建路径中。

如果libs文件夹尚不存在,请在项目的根目录下创建一个。

答案 2 :(得分:0)

鉴于您已升级到r18,您可能无法更改依赖关系管理。例如,请参阅this linkthis link