首页 > 解决方案 > android异常:找不到活动

问题描述

我的应用程序崩溃了。
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.smartmedicineapplication/com.example.smartmedicineapplication.ProfActivity}; have you declared this activity in your AndroidManifest.xml?

这是我的清单文件:

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

    <application
        android:name=".app.App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="com.example.smartmedicineapplication.ProfActivity"/>
        <activity android:name=".CreateNotificationActivity" />
        <activity android:name=".MainScreenActivity" />
        <activity android:name=".ChangePasswordActivity" />
        <activity android:name=".SignUpActivity" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

在我的活动中_尝试做这样的事情:

  @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
        switch (menuItem.getItemId()) {
            case R.id.nav_share:
                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.nav_share_text));
                startActivity(Intent.createChooser(sharingIntent, getString(R.string.open_with)));
                break;
            case R.id.nav_settings:
                Intent intent = new Intent(this, ProfActivity.class);
                startActivity(intent);
                break;
        }
        return false;

这是我的个人资料活动:

package com.example.smartmedicineapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class ProfActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prof);
    }
}

我读过同样的问题,但没有任何帮助。我不明白为什么会这样。请帮助我。

标签: androidandroid-manifest

解决方案


您的清单看起来不错。只需将活动名称与点 .ProfActivity 一起放在清单中,然后执行以下步骤。

1-仔细检查您的项目结构

2-尝试创建另一个测试活动并替换为 ProfActivity 并检查它是否有效

3-清理您的项目并重新启动 Android Studio

4-在再次运行您的构建之前,从您的设备中卸载以前的构建


推荐阅读