編輯:關於Android編程
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添加進來,注意包的重復問題,這一塊不容易說清楚,自己按情況進行解決。
補充:其他可以使用的方法
1.在項目的properties中的Java Build Path裡將Order and Export裡的android-support-v4.jar勾選上。
2.最簡單的在項目上右鍵Android Tools選FIx Project Properties。
今天我們要實現的這個view沒有太多交互性的view,所以就繼承view。自定義view的套路,套路很深 1、
近日,微信悄然上線了個人公眾號改名功能,據悉,微信在原賬號名稱下方會有一行“個人類賬號一年內可主動修改一次名稱”的標注,每年只有一次
ActivityManager.RunningAppProcessInfo類與獲取正在運行的應用程序每一個應用程序都會運行在它獨立的進程裡,但是為了節省資源或者這些應用程
Android上的界面展示都是通過Activity實現的,Activity實在是太常用了,我相信大家都已經非常熟悉了,這裡就不再贅述。 但是Activity也有它的局限性