出错提示:
android.content.ActivityNotFoundException:
Unable to find explicit activity class
1. 刚开始发现这个问题,觉得是代码有问题,但实际上并不是。
CODE snipet
@Override
public void onClick(View v) {
Intent intent = CrimeActivity.newIntent(getActivity(), mCrime.getId());
startActivity(intent);
}
2. Solution
依据提示”have you declared this activity in your
AndroidManifest.xml?”,可以明白大概方向,google一处1,基本上就知道在AndroidManifest.xml中少了部分,只是我不太明白为什么非要在这里注册呢?
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.york.android.criminalintent"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".CrimeActivity"></activity>
<activity android:name=".CrimeListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
后记
From this code, I learned lately that this code let the
OS can start it.
…to the manifest so that the OS can start
it.