android - 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);
}
}
我读过同样的问题,但没有任何帮助。我不明白为什么会这样。请帮助我。
解决方案
您的清单看起来不错。只需将活动名称与点 .ProfActivity 一起放在清单中,然后执行以下步骤。
1-仔细检查您的项目结构
2-尝试创建另一个测试活动并替换为 ProfActivity 并检查它是否有效
3-清理您的项目并重新启动 Android Studio
4-在再次运行您的构建之前,从您的设备中卸载以前的构建
推荐阅读
- algorithm - 如何计算此设计要求中需要多少 TB?
- git - 撤消恢复到上次提交
- jquery - 如何使用 CSS/Boostrap 和 Jquery 使粘性页眉和页脚具有箭头按钮以显示/隐藏内容为 Google Adsense
- python - 返回最佳 RMSE 和一个范围内所有值的列表的函数
- asynchronous - 无法在异步函数中更改 pathBuff/path 变量
- docker - 将 docker 图像从一个 acr 移动到另一个(docker images --format 选项不执行 docker tag , docker push )
- angular - 引擎盖下的 Angular Material Paginator
- validation - 我的项目 Vue 3 vuelidate 一样不工作
- azure - 需要帮助来复制文档布局并替换复制文档中的值
- android - 使用 Firebase 动态链接在 Flutter 应用中打开网页 url 内容