私が開発しているアプリが私をいじっています。現在、3 つのアクティビティがあり (すべてマニフェストで定義されています)、すべてが相互に移行します。つまり、イントロ -> アクティビティ 1 -> アクティビティ 2 です。イントロから最初のアクティビティへの移行は、次を使用して正常に機能します。
public void GOTOGPS(View v)
{
switch (v.getId()){
case R.id.button1: startActivity(new Intent(v.getContext(), StreetLightOutageActivity.class));//Jump to StreetLightOutageActivity (main.xml)
default: break;
}//switch
}//GOTOGPS
ただし、3 番目のアクティビティに移動するために使用される 2 番目のアクティビティ「StreetLightOutageActivity」のメソッドは機能しません。
public void GOTOCAMERA1(View v)
{
switch (v.getId()){
case R.id.picturebutton: startActivity(new Intent(v.getContext(), Camera.class));
default: break;
}//switch
}//GOTOCAMERA1
LogCat で ActivityNotFoundException が返されます。
05-17 15:51:41.292: E/AndroidRuntime(534): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {sl.reporter/android.hardware.Camera}; have you declared this activity in your AndroidManifest.xml?
そして、前の例外に起因すると思われる InvocationTargetException :
05-17 15:51:41.292: E/AndroidRuntime(534): Caused by: java.lang.reflect.InvocationTargetException
ここで本当に気になったのは、StreetLightOutageActivity.class ではなく「Camera.class」に移動するように、イントロ画面から 2 番目のアクティビティに移行するようにメソッドを変更すると、機能することです。
最後に、これが役立つ場合に備えて、私のマニフェストです。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sl.reporter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:icon="@drawable/ic_launcher">
<activity
android:name=".StreetLightOutageActivity">
</activity>
<activity
android:name=".Camera">
</activity>
<activity
android:name=".Introscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>