我跟着幾個教程,我發現這個錯誤未解決。 這是我的代碼。我的應用程序每次運行2秒後都會意外停止(預設定時器)應用程序意外停止Android開發
錯誤是:應用程序Test(process com.juicy.test)已意外停止。請再試一次。它會提示AVD。
W/dalvikvm(281):線程ID = 7:螺紋與未捕獲的異常 離開(組= 0x4001d800)
E/AndroidRuntime(281):致命異常:螺紋8
ë/AndroidRuntime(281):android.content.ActivityNotFoundException:否 活動發現處理意圖{行爲= com.juicy.test.MAINACTIVITY}
E/AndroidRuntime(281):在 android.app.Instrumentation.checkStartActivityResult (儀器廠entation.java:1408)
E/AndroidRuntime(281):在 android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
E/AndroidRuntime(281):在 android.app。 Activity.startActivityForResult(Activity.java:2817)
E/AndroidRuntime(281):在 android.app.Activity.startActivity(Activity.java:2923)
E/AndroidRuntime(281):在玉米.juicy.test.Tree $ 1.run(Tree.java:24)**
Tree.xml
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tree);
Thread timer = new Thread(){
public void run(){
try{
sleep(2000);
}catch(InterruptedException e){
e.printStackTrace();
}
finally{
Intent openMainActivity = new Intent("com.juicy.test.MAINACTIVITY");
startActivity(openMainActivity);
}
}
};
timer.start();
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.juicy.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Tree"
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=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.juicy.test.MAINACTIVITY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.juicy.test;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
int counter;
Button add, sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
display.setText("Your total is " + counter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
安置自己的錯誤日誌 – 2014-09-11 10:55:49
張貼您的logcat,以便我們可能知道錯誤在哪裏... – Umair 2014-09-11 10:56:01
對不起,我已經將這些logcat錯誤添加到我的文章。 – Danzeeeee 2014-09-11 11:05:41