java.lang.ClassNotFoundException Android

时间:2017-11-13 23:07:46

标签: android

在我将项目移动到另一个文件夹之前,我非常确定我的项目是否正常工作,然后我在Android工作室中将其移动回原始文件夹。当我运行它时,它现在有一个由

引起的错误
java.lang.ClassNotFoundException

您认为移动项目可能会导致这种情况吗?我已经检查了其他答案,我认为我的清单和build.gradle都可以。

模块build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.1'
    defaultConfig {
        applicationId "com.example.larry.project"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.google.code.gson:gson:2.7'
    testCompile 'junit:junit:4.12'
}

清单:

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

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

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

</manifest>

Project build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这些大多只是默认值,我不知道它是如何导致问题的。 错误:

11-12 15:55:25.405 4745-4745/com.example.larry.project E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: com.example.larry.project, PID: 4745
                                                                                  java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.larry.project/com.example.larry.project.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.larry.project.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.larry.project-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.larry.project-1/lib/x86, /system/lib, /vendor/lib]]
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:154)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                                   Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.larry.project.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.larry.lproject-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.larry.project-1/lib/x86, /system/lib, /vendor/lib]]
                                                                                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                      at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                                      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                      at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                                                                                      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                      at android.os.Looper.loop(Looper.java:154) 
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

我已经解决了我的问题并将其重新发布。

0 个答案:

没有答案