Android ClassNotFoundException: Didn't find cl

2018-12-31 19:35发布

10-22 15:29:40.897: E/AndroidRuntime(2561): FATAL EXCEPTION: main
10-22 15:29:40.897: E/AndroidRuntime(2561): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.gvg.simid/com.gvg.simid.Login}: java.lang.ClassNotFoundException: Didn't find class "com.gvg.simid.Login" on path: DexPathList[[zip file "/data/app/com.gvg.simid-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gvg.simid-1, /vendor/lib, /system/lib]]
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.os.Looper.loop(Looper.java:137)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.main(ActivityThread.java:5103)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.reflect.Method.invokeNative(Native Method)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.reflect.Method.invoke(Method.java:525)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at dalvik.system.NativeStart.main(Native Method)
10-22 15:29:40.897: E/AndroidRuntime(2561): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.gvg.simid.Login" on path: DexPathList[[zip file "/data/app/com.gvg.simid-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gvg.simid-1, /vendor/lib, /system/lib]]
10-22 15:29:40.897: E/AndroidRuntime(2561):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
10-22 15:29:40.897: E/AndroidRuntime(2561):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
10-22 15:29:40.897: E/AndroidRuntime(2561):     ... 11 more

I'm not really sure what is causing it as it is correctly listed in the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.gvg.simid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_LOGS" />
    <uses-permission android:name="android.permission.READ_OWNER_DATA" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-feature android:name="android.hardware.usb.host" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.gvg.simid.Login"
            android:label="@string/app_name" 
            android:screenOrientation="landscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

I also added "Android Private Libraries" to build path, and moved it to the top of "Order and Export", but it still gave me the same error.

EDIT: I rebuilt the project completely, and was unable to reproduce the error. Not sure what was causing it.

30条回答
临风纵饮
2楼-- · 2018-12-31 19:36

If you get this error while using the new Instant Run feature in Android Studio 2.0 and above then this is some kind of bug on their side.
To fix this you will have to stop your app manually on Device/Emulator if it's not stopped then from Android Studio select BuildRebuild Project.
Then click the Run button or SHIFT+F10

查看更多
春风洒进眼中
3楼-- · 2018-12-31 19:36

Solution mentioned here --> Multidex Issue solution worked for me. Below is what needs to be added to Application context :

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}
查看更多
只若初见
4楼-- · 2018-12-31 19:38

I had the same exact issue. As @weiweia suggested, move the code from the java directory to src worked for me. I also removed the Android Dependencies from Project --> Properties --> Java Build Path --> Order and Export, and made sure only to include Library Projects in the Android screen.

查看更多
公子世无双
5楼-- · 2018-12-31 19:40

1) Create libs folder under project root
2) Copy and paste the jar file into it
3) Configure the build path (Add jar)
4) Clean and run

cheers :-)

查看更多
浅入江南
6楼-- · 2018-12-31 19:41

Just in case anybody faces the same problem as me and no suggest answer here helps.

For me the cause was, that the Android studio refactor is buggy. I moved an innerclass outside of a class, which was a View and therefore also had a xml, where the direct path was set. This path will not get refactored by studio! And no error will be thrown.

Hope this helps anybody. Cheers.

查看更多
素衣白纱
7楼-- · 2018-12-31 19:42

I faced the same problem and solved it by doing the following:

From the build menu select

1- clean Project.

2- Build APK.

查看更多
登录 后发表回答