最近我在写安卓项目的时候,设计到一个intent的内容,设计到activity的跳转。但是在我运行项目时,出现了一个报错:E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.quotes, PID: 25663
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.quotes/com.example.quotes.QuoteDetail}; have you declared this activity in your AndroidManifest.xml?
通常这种情况下,你需要查看你的Manifest文件中是否注册了相应intent的activity标签就可以了:
<activity android:name=".QuoteDetail"/>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.quotes">
<application
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/Theme.Quotes">
<activity
android:name=".QuoteReaderActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".QuoteDetail"/>
</application>
</manifest>
然而我遇到的情况是:
我的Manifest文件和平时看到的内容和结构是不一样的,如下:
这种情况下,不管我怎么重新添加 <activity android:name=".QuoteDetail"/>, 他依然会报错,而且运行过程中manifest代码很诡异的自动回滚代码,我尝试了很多次都是失败了。
这种情况下,可以重建项目来解决,直接复制代码即可。然后解决知后的截图如下: