user3129072
user3129072

Reputation: 515

Android ClassNotFoundException: Didn't find class on path

I can't find the solution of this error. Can you please give the permanent solution? I have no idea how to solve it.

01-04 11:06:42.302: E/AndroidRuntime(1906): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{e.gochat/e.gochat.gochat.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "e.gochat.gochat.MainActivity" on path: DexPathList[[zip file "/data/app/e.gochat-1.apk"],nativeLibraryDirectories=[/data/app-lib/e.gochat-1, /vendor/lib, /system/lib]]
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2102)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.app.ActivityThread.access$700(ActivityThread.java:135)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.os.Looper.loop(Looper.java:137)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.app.ActivityThread.main(ActivityThread.java:4998)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at java.lang.reflect.Method.invokeNative(Native Method)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at java.lang.reflect.Method.invoke(Method.java:515)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at dalvik.system.NativeStart.main(Native Method)
01-04 11:06:42.302: E/AndroidRuntime(1906): Caused by: java.lang.ClassNotFoundException: Didn't find class "e.gochat.gochat.MainActivity" on path: DexPathList[[zip file "/data/app/e.gochat-1.apk"],nativeLibraryDirectories=[/data/app-lib/e.gochat-1, /vendor/lib, /system/lib]]
01-04 11:06:42.302: E/AndroidRuntime(1906):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
01-04 11:06:42.302: E/AndroidRuntime(1906):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
01-04 11:06:42.302: E/AndroidRuntime(1906):     ... 11 more
01-04 11:07:06.772: I/Process(1906): Sending signal. PID: 1906 SIG: 9
 

This is my app Manifest XML

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="e.gochat"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="18" />
<permission
    android:name="e.gochat.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="e.gochat.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
 
<application
    android:name="e.gochat.Common"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
   
    
    <activity
        android:name="e.gochat.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     <activity android:name="e.gochat.ChatActivity" 
        />
    <activity
        android:name="e.gochat.SettingsActivity"
        android:label="@string/title_activity_settings" />
    <receiver
        android:name="e.gochat.client.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="e.gochat" />
        </intent-filter>
    </receiver>
    <provider
        android:name="e.gochat.DataProvider"
        android:authorities="e.gochat.provider" 
        android:exported="false">
    </provider>
   
    
</application>
I'm not sure what's wrong here. I've added the .jar file in the java build path. And yet I'm getting this classnotfound exception. The app loads when I import the android.app.Application

Upvotes: 50

Views: 103882

Answers (13)

murgupluoglu
murgupluoglu

Reputation: 7194

If you tried other solutions and none of them work. Sometimes this error happens because some libraries use Java 8 features. To solve the problem, configure the Android Gradle Plugin to support Java 8 by adding the following code to your build.gradle file

compileOptions {
   sourceCompatibility JavaVersion.VERSION_1_8
   targetCompatibility JavaVersion.VERSION_1_8
}

Upvotes: 2

vaisakh mv
vaisakh mv

Reputation: 71

dependencies {
    implementation 'androidx.appcompat:appcompat:+'
    implementation 'androidx.constraintlayout:constraintlayout:+'
}

Remove this line from Gradle

Upvotes: 0

Michael McCormick
Michael McCormick

Reputation: 444

For me the issue occurred as I wasn't including the kotlin-android and kotlin-android-extensions plugins in my :app modules build.gradle.

E.g.

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

Or if you're using the Kotlin DSL

plugins {
    id("com.android.application")
    kotlin("android")
    kotlin("android.extensions")
}

Upvotes: 4

Zuop
Zuop

Reputation: 624

ANDROID STUDIO In addittion to Kishor's answer:

The error occured on my small project when I enabled multiDexEnabled = true in the gradle defaultconfig. Using the generated .apk file crashes on start of the app with the known error message.

For me it was solved when I built the .apk file via gradle (right side of android studio) -> "yourapp" -> Tasks- > install -> installDebug

Hope this helps someone with this strange error

Upvotes: 3

Kishor N R
Kishor N R

Reputation: 1591

I have solved this problem by disabling the instant run option of android studio. To disable Instant Run Goto File -> Settings -> Build,Execution, Deployment -> Instant Run -> Uncheck the checkbox for instant run

Upvotes: 36

Amit
Amit

Reputation: 3702

This issue has multiple answers based on the different scenario. I was getting the same error when using a library(.aar) in my Android Studio project.

The root cause in my case was that I missed to add a third party lib dependency in app's build.gradle file which was being used by the .aar file.

e.g:- The library(.aar) was using 'com.squareup.okhttp3:okhttp:3.4.1'. So I had to add

compile 'com.squareup.okhttp3:okhttp:3.4.1'

in the app's build.gradle. Hope it helps someone.

Upvotes: 6

prom85
prom85

Reputation: 17798

I implemented a listener that was not available in the android version I was running yet and this led to the same error.

Example MainActivity:

// RecyclerView.OnScrollChangeListener is only available on API >= 23
public class MainActivity implements RecyclerView.OnScrollChangeListener
{

}

Running this activity on a device with API < 23 will result in this error as well...

Upvotes: 2

Kushal
Kushal

Reputation: 8478

The problem was solved by removing MultiDexSupport from build.gradle file :

defaultConfig {
    multiDexEnabled true    // This line was causing above problem
}

Removing the MultiDexSupport solved the problem

Upvotes: 8

Tom Redman
Tom Redman

Reputation: 5650

For me, this was occurring on devices running < Android 5.0 because I didn't have multidex support enabled (this is, over 65k total methods incl. libs). Multidex is automatic and native on Android 5.0+ (specifically, devices using ART).

Upvotes: 10

live-love
live-love

Reputation: 52366

Uninstalling the app in the device and running the project again fixed it for me.

Upvotes: 13

Tyler
Tyler

Reputation: 19848

Using Android Studio

After upgrading to Android Stuido 0.8.2, I had this problem. I tried a lot of things, including

  • Clean project
  • Clean project (gradle clean)
  • Invalidate Caches and Restart
  • De-qualify the Activity Name in AndroidManifest.xml (.MyActivity)

Nothing worked until I re-imported the entire project.

File -> Close Project -> Import Project... -> Choose the same project -> OK

This fixed it for me

Upvotes: 13

Himadri Pant
Himadri Pant

Reputation: 2291

The reason why this was affecting me was due to an incorrect path name in a layout file

<android.support.v4.app.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"> 

</android.support.v4.app.view.ViewPager>

The correct absolute path of ViewPager is

android.support.v4.view.ViewPager

After correcting the path it worked. I did not have to prefix the activity name with a '.'.

Upvotes: 9

ramaral
ramaral

Reputation: 6179

I don't know for sure what is your package name, but if it is e.gochat do this.

Add package="e.gochat" to manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="e.gochat"
    .....
    .....
         >

On each activity declaration for android:name put a dot before activity name:

<activity
    android:name=".MainActivity">
............
</activity>

<activity 
    android:name=".ChatActivity">

EDIT

After your edited I can see e.gochat is your package name.
Now you only need to remove e.gochat from each activity/provider/receiver name as I said in second part of my answer.
Android will add that for you.

Upvotes: 35

Related Questions