0

我正在使用線程概念,即當我的應用程序加載它時,顯示圖片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) 

回答

1

而不是你的意圖使用該

新的意圖(WelcomeScreen.this,MainActivity.class)的;

+0

輝煌!它非常感謝你 – Rags 2014-11-08 18:05:44

1

這個問題的答案可能是

Intent startMainActivity = new Intent(this,MainActivity.class); 

我認爲這將有助於

0

您應指定要在清單中不是設置爲啓動這樣的默認活動:

<activity 
    android:name=".MainActivity" 
    android:label="@string/app_name" > 
</activity> 

然後你就可以簡單地開始了新的活動

startActivity(new Intent(this,MainActivity.class)); 
相關問題