Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

android - 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...