关于android-support-v4.jar包的错误

Posted brucemengbm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于android-support-v4.jar包的错误相关的知识,希望对你有一定的参考价值。

1.加入android-support-v4 误 java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loade

问题:在使用ViewPager加入android-support-v4.jar后提演示样例如以下错

11-15 21:01:21.725: E/AndroidRuntime(32431): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/mnt/asec/com.trinea.android.demo-2/pkg.apk]

 

完整错误为

我是通过项目 -> 属性 -> Java Build Path -> Add External JARs加入了android-support-v4.jar包的。解决仅仅须要项目 -> 属性 -> Java Build Path -> Remove该jar,直接将jar包拷贝到项目的libs文件夹下就可以。由于项目libs下的jar包会自己主动导入项目。不须要手动导入。自己主动导入的包存在在 Android Private文件夹下。

 

15 21:01:21.725: E/AndroidRuntime(32431): FATAL EXCEPTION: main
-15 21:01:21.725: E/AndroidRuntime(32431): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.trinea.android.demo/com.trinea.android.demo.ViewPagerDemo}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v4.view.ViewPager
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1664)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1680)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.os.Handler.dispatchMessage(Handler.java:99)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.os.Looper.loop(Looper.java:130)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.ActivityThread.main(ActivityThread.java:3703)
-15 21:01:21.725: E/AndroidRuntime(32431):     at java.lang.reflect.Method.invokeNative(Native Method)
-15 21:01:21.725: E/AndroidRuntime(32431):     at java.lang.reflect.Method.invoke(Method.java:507)
-15 21:01:21.725: E/AndroidRuntime(32431):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
-15 21:01:21.725: E/AndroidRuntime(32431):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
-15 21:01:21.725: E/AndroidRuntime(32431):     at dalvik.system.NativeStart.main(Native Method)
-15 21:01:21.725: E/AndroidRuntime(32431): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v4.view.ViewPager
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
-15 21:01:21.725: E/AndroidRuntime(32431):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:212)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.Activity.setContentView(Activity.java:1681)
-15 21:01:21.725: E/AndroidRuntime(32431):     at com.trinea.android.demo.ViewPagerDemo.onCreate(ViewPagerDemo.java:28)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
-15 21:01:21.725: E/AndroidRuntime(32431):     ... 11 more
-15 21:01:21.725: E/AndroidRuntime(32431): Caused by: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/mnt/asec/com.trinea.android.demo-2/pkg.apk]
-15 21:01:21.725: E/AndroidRuntime(32431):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
-15 21:01:21.725: E/AndroidRuntime(32431):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
-15 21:01:21.725: E/AndroidRuntime(32431):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.view.LayoutInflater.createView(LayoutInflater.java:471)
-15 21:01:21.725: E/AndroidRuntime(32431):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)


2.java.lang.ClassNotFoundException: Didn‘t find class "android.support.v4.view.ViewPager" on path: /data/app/XXX.apk

解决方式:把第三方的包(android-support-v4.jar)放在项目文件夹下的libs里,右键项目选择:Build Path -> use as source folder,就OK了。

然后Add jar 将android-support-v4.jar加入上来就可以。


总结:遇到这样的问题,解决方式就是须要将jar包导入到项目文件夹中,能够放在 Android private 中,这个是adt在载入项目的时候自己主动载入进来的,也能够直接自己Add jar加入进来,注意包的反复问题。这一块不easy说清楚,自己按情况进行解决。

 

补充:其它能够使用的方法

1.在项目的properties中的Java Build Path里将Order and Export里的android-support-v4.jar勾选上。

2.最简单的在项目上右键Android Tools选FIx Project Properties。

 



以上是关于关于android-support-v4.jar包的错误的主要内容,如果未能解决你的问题,请参考以下文章

android-support-v4在sdk哪个位置

导入3个SDK,报错:Found 3个版本的android-support-v4.jar

android-support-v7-appcompat 和 android-support-v4 之间的区别

android studio怎么导入jar包

Android - Jar mismatch! Fix your dependencies问题解决

Android - Jar mismatch! Fix your dependencies问题解决