无法在4.3和4.4中实例化活动,但可能在> 5.0中实例化

时间:2017-09-06 10:50:51

标签: android

我已经实现了一个在>上运行的应用Android 4.3 .. 经过大量的改动,它突然停止工作< Android 5.0但适用于> Android 5.0 .. 您可以在下面看到错误消息:

      E/AndroidRuntime: FATAL EXCEPTION: main
              java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.chickchat.chickchat/com.chickchat.chickchat.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.chickchat.chickchat.MainActivity" on path: DexPathList[[zip file "/data/app/com.chickchat.chickchat-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.chickchat.chickchat-1, /vendor/lib, /system/lib]]
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2137)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
                  at android.app.ActivityThread.access$600(ActivityThread.java:141)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:137)
                  at android.app.ActivityThread.main(ActivityThread.java:5103)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:525)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                  at dalvik.system.NativeStart.main(Native Method)
               Caused by: java.lang.ClassNotFoundException: Didn't find class "com.chickchat.chickchat.MainActivity" on path: DexPathList[[zip file "/data/app/com.chickchat.chickchat-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.chickchat.chickchat-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.Instrumentation.newActivity(Instrumentation.java:1061)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2128)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 
                  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 
                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                  at android.os.Looper.loop(Looper.java:137) 
                  at android.app.ActivityThread.main(ActivityThread.java:5103) 
                  at java.lang.reflect.Method.invokeNative(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:525) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                  at dalvik.system.NativeStart.main(Native Method) 

清单

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

    <application
        <activity
            android:name=".MainActivity"

android {
compileSdkVersion 26
buildToolsVersion '25.0.3'

Gradle.File

defaultConfig {
    applicationId "com.chickchat.chickchat"
    // Note: reducing to sdk 16 when removing UIAutomation
    minSdkVersion 18
    targetSdkVersion 26
    versionCode 1
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

dependencies {
compile 'com.android.support:multidex:1.0.1'
}

虽然在stackoverflow上存在很多关于此类Exception的问题,但我可以找到解决问题的方法......

1 个答案:

答案 0 :(得分:1)

似乎是multidex的一个问题。您的Application类是否从MultiDexApplication延伸,或者是否实施了必要的MultiDex.install(this)操作。

Configure Apps with Over 64K Methods