eclipse Android 无法实例化活动:未在路径上找到类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17273218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:46:36  来源:igfitidea点击:

Android Unable to instantiate activity: Didn't find class on path

javaandroideclipseclassandroid-activity

提问by bakua

I've imported project into eclipse and when I try to run it, then this exception is thrown:

我已经将项目导入到 eclipse 中,当我尝试运行它时,会抛出此异常:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.polygraf/com.polygraf.activity.Dashboard}: java.lang.ClassNotFoundException: Didn't find class "com.polygraf.activity.Dashboard" on path: /data/app/com.polygraf-1.apk

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.polygraf/com.polygraf.activity.Dashboard}: java.lang.ClassNotFoundException: Didn't find class "com.polygraf.activity.Dashboard" on path: /data/app/com.polygraf-1.apk

I've tried to clean the project, then check if all class names and manifest are ok, but still can't find why this happens. Can you help me a little please?

我试图清理项目,然后检查所有类名和清单是否正常,但仍然找不到发生这种情况的原因。你能帮我一点吗?

Dashbard class:

仪表盘类:

public class Dashboard extends FragmentActivity {

private static final String WELCOME_TYPE = "WELCOME_TYPE";
private static final String HELP_TYPE = "HELP_TYPE";

public static final String ADRESS_CONTENT = "ADRESS_CONTENT";
public static final String DOC_NAME = "DOC_NAME";

private Transcript mContent;
private ISettableContent mListOfDocument;

private String mAddress;

private String mDocName;

public Dashboard() {
}

/** Called with the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dashboard);

    boolean content = false;
    // View gc = (NoSaveStateFrameLayout)
    // findViewById(R.id.content_fragment);
    //

    Fragment frContent = getSupportFragmentManager().findFragmentById(R.id.content_fragment);
    mContent = ((IGetContent) frContent).getContent();
    TranscriptSetting cc = Polygraf.getInstance().getContentSetting();

    Fragment frDocumentsList = getSupportFragmentManager().findFragmentById(R.id.documents);
    mListOfDocument = (ISettableContent) frDocumentsList;
    cc.registerContent(mListOfDocument);

    if (getIntent().hasExtra(ADRESS_CONTENT)) {
        mAddress = getIntent().getStringExtra(ADRESS_CONTENT);
        mDocName = getIntent().getStringExtra(DOC_NAME);
        mContent.setAddress(mAddress, mDocName);
        content = true;
    } else if (getIntent().hasExtra(WELCOME_TYPE)) {
        content = true;
        prepareVisibilityBtnTranscript();
    } else if (getIntent().hasExtra(HELP_TYPE)) {
        content = true;
        mContent.showHelp();

    }

    if (content) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.hide(frDocumentsList);
        ft.commit();

        // because on diferent layouts for small and large device
        // some views missing, so the test is inportant
        View contentLayout = findViewById(R.id.contentLayout);
        if (contentLayout != null) {
            contentLayout.setVisibility(View.VISIBLE);
        }
        prepareVisibilityBtnWelcome();
        // cp.setContent(mContent);
    }

    cc.registerContent(mContent);
    // cp.setListener(cc);

}
    .
    .
    .
}

And manifest file:

和清单文件:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="17" />

<application
    android:name=".Polygraf"
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@drawable/icon"
    android:label="@string/skeleton_app"
    android:theme="@android:style/Theme.Black.NoTitleBar" >
    <activity
        android:name="com.polygraf.activity.Dashboard"
        android:configChanges="orientation|keyboard" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <!-- This places this activity into the main app list. -->
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.polygraf.activity.SettingActivity"
        android:label="@string/skeleton_app" />
    <activity
        android:name="com.polygraf.activity.ContentActivity"
        android:label="@string/skeleton_app" >
    </activity>
    <activity
        android:name="com.polygraf.activity.PlayVideo"
        android:configChanges="orientation|keyboard"
        android:label="@string/skeleton_app" />
</application>

回答by gunar

I suppose you're using Eclipse. Your activity is there alright, but Eclipse didn't include the support package in the APK ... If you look above your error in stacktrace you will notice the root of your problem: "Unable to find FragmentActivity". Or you can unpack the apk, undex it and you will see the compatibility package classes were not included.

我想您正在使用 Eclipse。您的活动在那里没问题,但 Eclipse 没有在 APK 中包含支持包……如果您查看堆栈跟踪中的错误上方,您会注意到问题的根源:“ Unable to find FragmentActivity”。或者,您可以解压缩 apk,对其进行解压缩,您将看到不包含兼容包类。

To fix this, right-click your project, properties, build path and go to export tab. There make sure "Android private libraries" are checked. A clean and rebuild should put you on track ...

要解决此问题,请右键单击您的项目、属性、构建路径并转到导出选项卡。确保“ Android private libraries”被选中。一个干净和重建应该让你走上正轨......

回答by Codreanu Andrei

After i spend a while on this problem, the solution that i found is a conflict between importing Properties > Android - appcompat_v7 and appcompat_v4 that was added in the libs folder. After i remove the appcompat_v4 the error no longer appear. I hope that answer can help in the future someone.

在我花了一段时间解决这个问题后,我发现的解决方案是导入 Properties > Android - appcompat_v7 和添加到 libs 文件夹中的 appcompat_v4 之间存在冲突。删除 appcompat_v4 后,错误不再出现。我希望这个答案可以在未来帮助某人。

回答by Yash

You should import new appcompat_v7 from sdk and use it as a built path,it works for me.

您应该从 sdk 导入新的 appcompat_v7 并将其用作构建路径,它对我有用。