在我的应用程序中,我从logcat收到以下错误,我的代码有什么错误?我在网上搜索了一个多小时,无法解决问题。
它与我想要使用的意图有关,以便打开一个新活动,但我不知道如何解决它。
07-20 20:02:18.976: E/AndroidRuntime(7381): FATAL EXCEPTION: Thread-9022
07-20 20:02:18.976: E/AndroidRuntime(7381): Process: com.example.brianapp, PID: 7381
07-20 20:02:18.976: E/AndroidRuntime(7381): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.brianapp.MeditationResults }
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivityForResult(Activity.java:3511)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivityForResult(Activity.java:3472)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivity(Activity.java:3714)
07-20 20:02:18.976: E/AndroidRuntime(7381): at android.app.Activity.startActivity(Activity.java:3682)
07-20 20:02:18.976: E/AndroidRuntime(7381): at com.example.brianapp.Meditation$2.run(Meditation.java:115)
与此代码部分有关,因为只有在我更改此代码部分后才会出现此错误:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.meditation);
//new thread
Thread timer = new Thread() {
/**
* Method that firstly starts the thread and makes it sleep,
* then using intents opens the main activity using
* a reference to its name
*/
public void run() {
try {
//sleep for 3.5 seconds
sleep(15000);
} catch (InterruptedException e) {
// exceptions caught here
e.printStackTrace();
} finally {
Intent openActivity = new Intent("com.example.brianapp.MeditationResults");
// //Start activity
startActivity(openActivity);
}
}
};
//Start timer
timer.start();
以下是我的清单,请注意我已经为此类包含了一个intent过滤器(冥想),我试图用意图打开的类称为MeditationResults:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.brianapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.brianapp.Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.brianapp.menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.Meditation"
android:label="Meditation" >
<intent-filter>
<action android:name="com.example.brianapp.meditation" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="@string/title_activity_meditation_results" >
</activity>
<activity
android:name="com.example.brianapp.UserName"
android:label="@string/title_activity_user_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.brianapp.ServerInterface"
android:label="@string/title_activity_server_interface" >
</activity>
</application>
</manifest>
答案 0 :(得分:1)
将清单中的内容更改为
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="@string/title_activity_meditation_results" >
</activity>
到
<activity
android:name="com.example.brianapp.MeditationResults"
android:label="@string/title_activity_meditation_results" >
<intent-filter>
<action android:name="com.example.brianapp.MeditationResults" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>