我正在使用线程概念,即当我的应用程序加载它时,显示图片3秒,然后加载活动。 但我得到一个活动未发现异常使用意图启动新活动时发生活动未发现异常
WelcomeScreen-1活性(负载并停留3secs) MainActivity-2号活性的SHLD开始计时后。(抛出错误说不幸的是停止)。 我对Android完全陌生,这是我第一个应用程序。请不要重复。 由于提前
WelcomeScreen代码:
public class WelcomeScreen extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcomescreen);
Thread thread=new Thread(){
public void run(){
try{
sleep(3000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent startMainActivity = new Intent("com.thenewboston.helloworld.MainActivity");
startActivity(startMainActivity);
}
}
};thread.start();
}
}
MainActivity代码:
public class MainActivity extends ActionBarActivity {
int counter;
Button add, sub;
TextView displayTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
counter=0;
add=(Button) findViewById(R.id.addButton);
sub=(Button) findViewById(R.id.subButton);
displayTxt=(TextView) findViewById(R.id.textView1);
add.setOnClickListener(new View.OnClickListener(
) {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
displayTxt.setText("Your Count is "+counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
displayTxt.setText("Your Count is "+counter);
}
});
}
Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thenewboston.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.thenewboston.helloworld.WelcomeScreen"
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.thenewboston.helloworld.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
logcat的日志:
11-08 12:55:03.172: D/dalvikvm(1994): GC_FOR_ALLOC freed 58K, 5% free 2891K/3032K, paused 58ms, total 61ms
11-08 12:55:03.172: I/dalvikvm-heap(1994): Grow heap (frag case) to 8.050MB for 5404816-byte allocation
11-08 12:55:03.242: D/dalvikvm(1994): GC_FOR_ALLOC freed 2K, 2% free 8166K/8312K, paused 63ms, total 63ms
11-08 12:55:04.462: D/gralloc_goldfish(1994): Emulator without GPU emulation detected.
11-08 12:55:07.152: W/dalvikvm(1994): threadid=11: thread exiting with uncaught exception (group=0xb2a9aba8)
11-08 12:55:07.172: E/AndroidRuntime(1994): FATAL EXCEPTION: Thread-129
11-08 12:55:07.172: E/AndroidRuntime(1994): Process: com.thenewboston.helloworld, PID: 1994
11-08 12:55:07.172: E/AndroidRuntime(1994): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.thenewboston.helloworld.MAINACTIVITY }
11-08 12:55:07.172: E/AndroidRuntime(1994): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
11-08 12:55:07.172: E/AndroidRuntime(1994): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
11-08 12:55:07.172: E/AndroidRuntime(1994): at android.app.Activity.startActivityForResult(Activity.java:3424)
11-08 12:55:07.172: E/AndroidRuntime(1994): at android.app.Activity.startActivityForResult(Activity.java:3385)
11-08 12:55:07.172: E/AndroidRuntime(1994): at android.app.Activity.startActivity(Activity.java:3627)
11-08 12:55:07.172: E/AndroidRuntime(1994): at android.app.Activity.startActivity(Activity.java:3595)
11-08 12:55:07.172: E/AndroidRuntime(1994): at com.thenewboston.helloworld.WelcomeScreen$1.run(WelcomeScreen.java:22)
辉煌!它非常感谢你 – Rags 2014-11-08 18:05:44