0

我正在使用 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
4

3 回答 3

7

it is perhaps that the version of android-support-v4.jar is not right. solution:

  1. close the eclipse
  2. delete the android-support-v4.jar in the project's libs folder
  3. reopen the eclipse
  4. right click the project, Android Tools -> Add Support Library... then the eclipse will download the right version of android-support-v4.jar for your project and add it to your project.
  5. rebuilt and run your project, it will OK!
于 2012-12-05T14:25:56.583 回答
0

Given that you upgraded to r18, you might be having trouble with the changes to dependency management. See this link and this link for example.

于 2012-04-13T20:37:37.483 回答
0

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

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

于 2012-04-13T17:45:48.117 回答