qiantujava
没钱吃肉
2018-01-06 07:40

加上自定义Application之后报错(ClassNotFoundException)

40
  • android

相关代码

Application类:

package com.weyes.focus;

import android.app.Application;

public class MyApplication extends Application {}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.weyes.focus">

    <application
        android:name="com.weyes.focus.MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

问题描述

添加:android:name="com.weyes.focus.MyApplication"
项目在安卓5.0以上运行都没有问题。
在4.x上运行报错。我这里三台手机都报错,红米(4.2.1)、三星(4.3)、酷派(4.4.4)。

删除:android:name="com.weyes.focus.MyApplication"
所有手机运行正常。

报错信息

01-06 15:28:08.720 25650-25650/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   java.lang.RuntimeException: Unable to get provider com.luck.picture.lib.PictureFileProvider: java.lang.ClassNotFoundException: Didn't find class "com.luck.picture.lib.PictureFileProvider" on path: DexPathList[dexElements=[zip file "/data/app/com.weyes.focus-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.weyes.focus-1, /vendor/lib, /system/lib]]
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:5115)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4670)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4606)
                                                       at android.app.ActivityThread.access$1300(ActivityThread.java:162)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
                                                       at android.os.Handler.dispatchMessage(Handler.java:99)
                                                       at android.os.Looper.loop(Looper.java:153)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5383)
                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:511)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
                                                       at dalvik.system.NativeStart.main(Native Method)
                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.luck.picture.lib.PictureFileProvider" on path: DexPathList[dexElements=[zip file "/data/app/com.weyes.focus-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.weyes.focus-1, /vendor/lib, /system/lib]]
                                                       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:5100)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4670) 
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4606) 
                                                       at android.app.ActivityThread.access$1300(ActivityThread.java:162) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                       at android.os.Looper.loop(Looper.java:153) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5383) 
                                                       at java.lang.reflect.Method.invokeNative(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:511) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
                                                       at dalvik.system.NativeStart.main(Native Method) 

这里报错说找不到这个类com.luck.picture.lib.PictureFileProvider,其实不单单是这个类,而是所有类都找不到,但这些类确实都是存在的,也就是类加载的时候就有问题了,实在不知道哪里出了问题,哪路大神碰过类似的问题么?求指教!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答