I'm a bit stuck on this. Android is throwing a ClassNotFoundException
even though there is such a class.
04-20 09:07:50.179: E/AndroidRuntime(525): FATAL EXCEPTION: main
04-20 09:07:50.179: E/AndroidRuntime(525): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.company.app/com.company.app.Main}: java.lang.ClassNotFoundException: com.company.app.Main
04-20 09:07:50.179: E/AndroidRuntime(525): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.os.Looper.loop(Looper.java:137)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-20 09:07:50.179: E/AndroidRuntime(525): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 09:07:50.179: E/AndroidRuntime(525): at java.lang.reflect.Method.invoke(Method.java:511)
04-20 09:07:50.179: E/AndroidRuntime(525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-20 09:07:50.179: E/AndroidRuntime(525): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-20 09:07:50.179: E/AndroidRuntime(525): at dalvik.system.NativeStart.main(Native Method)
04-20 09:07:50.179: E/AndroidRuntime(525): Caused by: java.lang.ClassNotFoundException: com.company.app.Main
04-20 09:07:50.179: E/AndroidRuntime(525): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-20 09:07:50.179: E/AndroidRuntime(525): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-20 09:07:50.179: E/AndroidRuntime(525): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
04-20 09:07:50.179: E/AndroidRuntime(525): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
04-20 09:07:50.179: E/AndroidRuntime(525): ... 11 more
There is such a class called Main
in Main.java
.
public class Main extends FragmentActivity
which is in the package com.company.app
.
It was working before but when I went back to work on the app today it just stopped working. I don't know what happened.
It is defined correctly in the Manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light" >
<activity
android:label="@string/app_name"
android:name=".Main" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Few things I've tried:
- Restarting Eclipse
- Restarting the emulator
- Uninstalling and reinstalling the app in the emulator
- Cleaning the project.
- Checking if
gen
andsrc
is in theSource
tab of the build path.
As it looks right now, I may have to abandon the current project and start from scratch.
Any help would be much appreciated.
UPDATE:
The app works if Main
extends Activity
instead of FragmentActivity
. Perhaps it is something with the Android Support package?
UPDATE 2:
I'm pretty sure it is. When I don't use the support package and I use the normal Fragment
classes in Android 3.0 and up, the app works fine.
The problem is now fixed. :)
For some reason the Android support package removed itself from the /libs
directory in the project and it was referencing it from an external location (outside the workspace
directory).
I will mark Abdu Egal's first answer as correct as he directed me on the right track.