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
user3129072
  • 515
  • 1
  • 4
  • 8

13 Answers13

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.

ramaral
  • 6,149
  • 4
  • 34
  • 57
  • 1
    Why does dot have to be used before Activity name? Why can't provide the full package path for Activity name?? – IgorGanapolsky Aug 09 '16 at 16:28
  • @IgorGanapolsky You can provide the full path if `package="e.gochat"` is not used(is removed). – ramaral Aug 09 '16 at 17:36
  • 1
    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. – Hazim Aug 01 '17 at 12:04
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

Kishor N R
  • 1,521
  • 1
  • 17
  • 23
  • 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. – CodeToLife Jun 23 '17 at 12:39
  • @CodeToLife Same problem here - I think a lot of people will google solution and get to this page. Hopefully they'll see this answer... – nikib3ro Sep 28 '17 at 17:03
  • you saved my life Thank you very much – blkrt Nov 06 '17 at 08:56
  • 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 life – Pranoy Sarkar Nov 18 '17 at 17:36
  • this worked for me! but i do not know, what is the reason?! – Ali Soleimani Mar 07 '18 at 09:14
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

Tyler
  • 19,113
  • 19
  • 94
  • 151
12

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

live-love
  • 48,840
  • 22
  • 240
  • 204
  • 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.o – BenJaminSila Sep 25 '16 at 06:28
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 '.'.

Himadri Pant
  • 2,171
  • 21
  • 22
  • 1
    You save my day , that happen in my project and specially in package com.neopixl.pixlui.MainActivity Thanks a lot – Ahmed Salem Dec 22 '15 at 06:41
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).

Tom Redman
  • 5,592
  • 4
  • 34
  • 42
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

Kushal
  • 8,100
  • 9
  • 63
  • 82
  • 4
    Well, adding this line fixed the error for me, Thanks :) any explanation for this? – DAVIDBALAS1 Aug 17 '16 at 14:23
  • 1
    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 resolved – Kushal Aug 19 '16 at 12:40
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.

Amit
  • 3,422
  • 3
  • 28
  • 39
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")
}
  • 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: https://developer.android.com/kotlin/add-kotlin Using `Help` -> `Find Action` I got the `Configure Kotlin` dialog and that edited gradle automatically for me. – Joshua Mar 17 '23 at 18:33
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

Zuop
  • 584
  • 5
  • 7
  • 21
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...

prom85
  • 16,896
  • 17
  • 122
  • 242
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
}
murgupluoglu
  • 6,524
  • 4
  • 33
  • 43
0
dependencies {
    implementation 'androidx.appcompat:appcompat:+'
    implementation 'androidx.constraintlayout:constraintlayout:+'
}

Remove this line from Gradle

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
vaisakh mv
  • 71
  • 5