简体   繁体   中英

Class not found exception in my android app

I have seen many issue similar to this and tried almost all solution. But nothing is working. On android emulator app works good but when i try in my device it throws java.lang.ClassNotFoundException: in.thoughtsmith.jobsmith.SplachScreenActivity.

  java.lang.RuntimeException: Unable to instantiate activity
   ComponentInfo{in.thoughtsmith.jobsmith/in.thoughtsmith.jobsmith.SplachScreenActivity}: java.lang.ClassNotFoundException: in.thoughtsmith.jobsmith.SplachScreenActivity
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)                                                                              
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2143)
 at android.app.ActivityThread.access$700(ActivityThread.java:140)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
 at android.os.Handler.dispatchMessage(Handler.java:99)
 at android.os.Looper.loop(Looper.java:174)
 at android.app.ActivityThread.main(ActivityThread.java:4952)
 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:1027)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
 at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: in.thoughtsmith.jobsmith.SplachScreenActivity
 at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
 at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2143) 
 at android.app.ActivityThread.access$700(ActivityThread.java:140) 
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237) 
 at android.os.Handler.dispatchMessage(Handler.java:99) 
 at android.os.Looper.loop(Looper.java:174) 
 at android.app.ActivityThread.main(ActivityThread.java:4952) 
 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:1027) 
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) 
 at dalvik.system.NativeStart.main(Native Method) 

i have seen my manifest everything looks fine

<application
    android:name="in.thoughtsmith.jobsmith.JobSmithApplication"
    android:allowBackup="true"
    android:icon="@drawable/logo_only"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name="in.thoughtsmith.jobsmith.SplachScreenActivity"
        android:noHistory="true"
        android:theme="@android:style/Theme.Light.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="in.thoughtsmith.jobsmith.MapsActivity"
        android:label="@string/title_activity_maps" />
    <activity android:name="in.thoughtsmith.jobsmith.JobSearchResultActivity" />
    <activity
        android:name="in.thoughtsmith.jobsmith.LoginActivity"
        />

    <service
        android:name="in.thoughtsmith.jobsmith.LocationCheckerService"
        android:enabled="true"
        android:exported="true" />

    <activity android:name="in.thoughtsmith.jobsmith.FusedApiTestActivity" />
    <activity android:name="in.thoughtsmith.jobsmith.ProfileUpdateActivity"></activity>
</application>

I want to make it clear that this app works fine in emulator and mobile device. But causes issue with on my device in which i was testing[ but it was working few days before on same device]. Is this possible that some thing may be worng with my device.

Many devices not work with instant run with debug mode so follow below steps

Disable instant run -

  1. Click setting in file menu and search instant run and unchecked all check boxes and build apk again.

在此处输入图片说明

Also Disable proguard in debug mode.

debug {
            minifyEnabled false
            useProguard false 

        }

Disable proguard and try

In your app level build.gradle file,

android {

    compileSdkVersion 25
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "in.thoughtsmith.jobsmith"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }

    buildTypes {
        debug {
            minifyEnabled false
            useProguard false <-------------------------------
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
        }
        release {
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM