ClassNotFoundException: Didn't find class "com.example.app.MainActivity" for every app I create
E

2

8

I keep getting a ClassNotFoundException every time I create an Android application in Eclipse. This is something that has never happened before up until this morning after using Eclipse for months. It might also be worth mentioning that I installed google play services through the SDK manager this morning

Logcat:

11-03 12:39:29.080: E/AndroidRuntime(27547): FATAL EXCEPTION: main
11-03 12:39:29.080: E/AndroidRuntime(27547): Process: com.example.app, PID: 27547
11-03 12:39:29.080: E/AndroidRuntime(27547): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.app/com.example.app.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.app.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.app-1, /vendor/lib, /system/lib]]
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.app.ActivityThread.access$900(ActivityThread.java:161)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.os.Handler.dispatchMessage(Handler.java:102)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.os.Looper.loop(Looper.java:157)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.app.ActivityThread.main(ActivityThread.java:5356)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at java.lang.reflect.Method.invokeNative(Native Method)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at java.lang.reflect.Method.invoke(Method.java:515)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at dalvik.system.NativeStart.main(Native Method)
11-03 12:39:29.080: E/AndroidRuntime(27547): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.app.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.app-1, /vendor/lib, /system/lib]]
11-03 12:39:29.080: E/AndroidRuntime(27547):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
11-03 12:39:29.080: E/AndroidRuntime(27547):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)

Manifest.xml:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Eclipse:

enter image description here

enter image description here

Eucharis answered 3/11, 2014 at 12:47 Comment(13)
post your manifest.xmlDnepropetrovsk
I think you missed to define MainActivity class in Manifest.xml fileCiaracibber
u r not added class in mainfest file please checkTaut
check your manifest file whether you've added an entry for the activity. if yes, clean the project(Project > Clean) and runOfficialdom
manifest added. this is the manifest file that was generated automatically. I will clean and run nowEucharis
Check : #10866931Dollarfish
@cbrook check my answer and change your manifest, it should fix your problemMcneese
@cbrook,please check my link problem is not related Activity declaration.Dollarfish
ok will check link now, thank youEucharis
Yes, see Haresh's link. You activity is being dropped on install due to an unsatisfied dependency on ActionBarActivity due to improper referencing of the support library.Polychrome
I see. So it is the way I am making a reference to the appcompat library?Eucharis
I have tried re-referencing like it says in the link but I am just getting errors in my code now :/Eucharis
Taking out the usage of ActionBarActivity has fixed the problem so it clearly was the way that I was referencing the appcompat actionbar library. I've tried referencing using the method in the link but still no luckEucharis
M
7

Open your AndroidManifest.xml and check if you have com.example.app.MainActivity :

    <activity
        android:name="com.example.app.MainActivity"
        android:label="@string/app_name" >
    </activity>
Mcneese answered 3/11, 2014 at 12:51 Comment(12)
@BT What's different between OP's manifest and your answer?Dnepropetrovsk
OP might have moved the activity to different package without changing the manifest.Lamia
Still crashes I'm afraidEucharis
He use android:name=".MainActivity" instead of the full package.Mcneese
@cbrook check if the activity is located in exactly same package.Lamia
@cbrook please open your MainActivity.java and see the importMcneese
@BlazeTama the .MainActivity will only concatenate to package="com.example.app".Lamia
shown at the top of MainActivity.java package com.example.app;Eucharis
@Lamia do you mean its same with my answer? Sorry i dont know about that. This is strange..Mcneese
@cbrook please post your project structure.Lamia
This is clearly not the right answer, don't upvote it.Gruber
this is the correct answer for this issue : #62728862Arlindaarline
F
0

Delete the android folder then add again

if you using Capacitor you can use below command

npx cap add android
Fiendish answered 3/8 at 7:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.