我正在尝试打开一个启动活动,然后是主要活动。但是我在logcat中遇到以下错误。
01-20 16:46:45.568: E/AndroidRuntime(29579): FATAL EXCEPTION: main
01-20 16:46:45.568: E/AndroidRuntime(29579): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cyoa.necroprelude/com.cyoa.necroprelude.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.cyoa.necroprelude.CHARACTER }
活动代码 - 主要活动
package com.cyoa.necroprelude;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends Activity {
Intent openStartingPoint;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
run();
}
private void run() {
Intent openStartingPoint = new Intent("com.cyoa.necroprelude.CHARACTER");
startActivity(openStartingPoint);
}
}
活动代码 - 角色活动
package com.cyoa.necroprelude;
import android.app.Activity;
import android.os.Bundle;
public class Character extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.character);
}
}
这是清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyoa.necroprelude"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.cyoa.necroprelude.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.cyoa.necroprelude.Character"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.CHARACTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:0)
更改
Intent openStartingPoint = new Intent("com.cyoa.necroprelude.CHARACTER");
到
Intent openStartingPoint = new Intent(this, CHARACTER.class);
String CUSTOM_ACTION = "android.intent.action.CHARACTER";
openStartingPoint.setAction(CUSTOM_ACTION);
答案 1 :(得分:0)
创建打开另一个屏幕的意图时,请确保它看起来像以下
Intent intent = new Intent(thisScreen.this, newScreen.class);
startActivity(intent);