FragmentActivity 导致 ClassNotFoundException [英] FragmentActivity causing ClassNotFoundException

查看:27
本文介绍了FragmentActivity 导致 ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用 Android SDK Manager 将 Android SDK 工具更新到第 17 版,并将 Android 兼容性更新到第 7 版.现在,我运行多年的程序在启动时崩溃了.

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.

缩小问题范围,我创建了一个新的空白项目,将 android-support-v4.jar 添加到构建路径,并将 Activity 更改为 FragmentActivity ,仅此而已.现在它崩溃了.

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.

错误信息是:

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

代码是:

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!

清单包括在下面:

<?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>

推荐答案

原来是 Android SDK Tools r17 的问题.我之前一直在使用教程中给出的方法:

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/教程/android/android-compatibility-working-with-fragments/

但是,这不再有效.相反,我需要做的就是在 Eclipse 中右键单击我的项目并选择 Android Tools-->Add Support Library...

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...

这样做意味着不再需要转到 Java 构建路径并单击添加外部 JAR..."

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

非常感谢 eMich 提供以下解决方案:ADT r17 的 Jar 文件问题

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

这篇关于FragmentActivity 导致 ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆