Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FragmentActivity causing ClassNotFoundException

I just used Android SDK Manager to update Android SDK Tools to revision 17, and Android Compatiblity to revision 7. Now, the program I've been running for ages crashes on startup.

Narrowing down the issue, I have created a new blank project, added android-support-v4.jar to the build path, and changed Activity to FragmentActivity and that's all. Now it crashes.

The error message is:

java.lang.ClassNotFoundException: com.example.test.TestActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.test-2.apk]

The code is:

package com.example.test;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class TestActivity extends FragmentActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Everything else, including the manifest, is unchanged from the defaults. Any help is much appreciated!

Edit: Manifest included below:

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

    <uses-sdk android:minSdkVersion="9" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TestActivity"
            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>
like image 242
Dave Avatar asked Mar 29 '12 18:03

Dave


2 Answers

Turns out it's a problem with Android SDK Tools r17. I had previously been using the method given in the tutorial at:

http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/

However, this no longer works. Instead, all I needed to do was right-click on my project in Eclipse and choose Android Tools-->Add Support Library...

Doing this means it is no longer necessary to go to Java Build Path and click "Add External JARs..."

Many thanks to eMich for this solution from: Jar-file issue with ADT r17

like image 151
Dave Avatar answered Nov 19 '22 00:11

Dave


I had the same issue and none of the answers I found in stackoverflow solved my problem. After hours of several (many) trial-and-error, I solved my problem by configuring build path of my project. In Eclipse, right click the project > Build Path > Configure Build Path..., in Order and Export tab, check Android Private Libraries, click OK. After that, clean up the project and try running again.

I solved this problem by comparing my project with other (newly created) project that could run as expected. I compared each configurations and AndroidManifest.xml of them.

Hope this helps you too :)

UPDATE Other solution: using ANT

I found another way to solve this problem: using ANT. My friend faced the same issue, but fixing the build path didn't solve his problem. I don't know whether it was because we use the different IDE version, different ADT version, or different operating system (I use GNU/Linux). And then, I suggested him to use ANT rather than the IDE's one.

First, setup the project (create build.xml) by executing android update project -p <project-dir> -n <project-name> for each project (including library projects). And then, from the main project's directory, execute ant debug to build, ant installd to install, and run the application.

The strange thing was, once he succeeded with this way, he even can compile by using IDE again, without ANT at all.

like image 45
fikr4n Avatar answered Nov 19 '22 00:11

fikr4n