Android ClassNotFoundException: Didn't find class on path
Asked Answered
O

13

50

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
Outrush answered 4/1, 2014 at 17:8 Comment(2)
Somewhere you are using e.gochat.gochat.MainActivity but you have declared the name e.gochat.MainActivity in AndroidManifest.xmlJorgenson
I had the same issue and fixed it with that solution : https://mcmap.net/q/330946/-classnotfoundexception-on-androidannotations-generated-classes-since-update-to-adt-22Coralloid
S
35

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.

Spies answered 4/1, 2014 at 17:35 Comment(3)
Why does dot have to be used before Activity name? Why can't provide the full package path for Activity name??Chary
@Chary You can provide the full path if package="e.gochat" is not used(is removed).Spies
Dears, i have faced same problem, and fix the package name as ramaral mention, but not fixed until I clean the project, then make project then build and run, and now it's working fine.Rebozo
A
35

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

Alkyne answered 6/4, 2017 at 6:5 Comment(5)
I wanteed to rename a project. After clossing Android Studio, renaming whole project in file explorer, and importing it with desired name again to Android Studio, it started the issue asked above in the original question . Your answer only helped.Autolycus
@Autolycus Same problem here - I think a lot of people will google solution and get to this page. Hopefully they'll see this answer...Preglacial
you saved my life Thank you very muchPsephology
I think android studio has serious bug , the project was working fine in api 17 but when i tried to debug on 24 it was through this exception, even though if i transfer the app through other means (via bluetooth ) the app was working fine in 24 , any way thanks for saving my lifeEpicurean
this worked for me! but i do not know, what is the reason?!Veritable
C
13

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

Chenoweth answered 22/7, 2014 at 22:44 Comment(0)
G
12

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

Guss answered 31/8, 2014 at 23:0 Comment(1)
Uninstalling and then running the app worked for me. Thanks. I run into this problem after not updating Android Studio for a while (many weeks). As of the writing of this post, I am now running this version -> Android Studio 2.2 Build #AI-145.3276617, built on September 15, 2016 JRE: 1.8.0_76-release-b03 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.oSundew
G
9

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 '.'.

Grackle answered 24/6, 2014 at 9:20 Comment(1)
You save my day , that happen in my project and specially in package com.neopixl.pixlui.MainActivity Thanks a lotMarienthal
O
9

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).

Outlaw answered 25/2, 2015 at 18:39 Comment(0)
T
7

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

Tyndall answered 4/11, 2015 at 10:22 Comment(2)
Well, adding this line fixed the error for me, Thanks :) any explanation for this?Climax
Android platform imposes 64K limit for size of referenced methods, to avoid this we can enable multi-dex support. So, I enabled multiDex support and my unfound classes were properly compiled into classes.dex and exception was resolvedTyndall
D
5

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.

Democracy answered 23/8, 2016 at 6:47 Comment(0)
I
3

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")
}
Insignificance answered 21/1, 2021 at 16:47 Comment(1)
This was my issue. I used Android Studio to convert my main activity to Kotlin and never got any warnings or prompts to configure it as described here: developer.android.com/kotlin/add-kotlin Using Help -> Find Action I got the Configure Kotlin dialog and that edited gradle automatically for me.Dactylography
S
2

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

Seaquake answered 20/9, 2017 at 22:48 Comment(1)
I have the same problemShoreless
L
1

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...

Liquorice answered 25/3, 2016 at 11:28 Comment(0)
L
1

If you tried other solitions and none of them work. Sometimes this error happen because some library use Java 8 features. To solve the problem, configure 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
}
Lordinwaiting answered 6/12, 2019 at 12:16 Comment(0)
M
0
dependencies {
    implementation 'androidx.appcompat:appcompat:+'
    implementation 'androidx.constraintlayout:constraintlayout:+'
}

Remove this line from Gradle

Medeiros answered 3/2, 2021 at 5:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.