2013-11-04 46 views
2

當我運行我的程序時出現此錯誤。它啓動了第一頁,但是當它應該去。菜單崩潰:Android:找不到處理意圖的活動

11-04 06:01:06.039: W/dalvikvm(949): threadid=11: thread exiting with uncaught exception (group=0x414c4700) 
11-04 06:01:06.057: E/AndroidRuntime(949): FATAL EXCEPTION: Thread-87 
11-04 06:01:06.057: E/AndroidRuntime(949): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.secondapp.MENU } 
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632) 
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) 
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivityForResult(Activity.java:3390) 
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivityForResult(Activity.java:3351) 
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivity(Activity.java:3587) 
11-04 06:01:06.057: E/AndroidRuntime(949): at android.app.Activity.startActivity(Activity.java:3555) 
11-04 06:01:06.057: E/AndroidRuntime(949): at com.example.secondapp.Splash$1.run(Splash.java:26) 

這裏是我的清單:

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.secondapp" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="11" 
     android:targetSdkVersion="18" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <activity 
      android:name=".Splash" 
      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=".Menu" 
      android:label="@string/app_name" > 
     <intent-filter> 
       <action android:name="android.intent.action.MENU" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 

     <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" > 
     <intent-filter> 
       <action android:name="android.intent.action.MAINACTIVITY" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 

    </application> 

</manifest> 

這裏是我的.Splash活動的.java文件和我的。菜單活動:

飛濺

package com.example.secondapp; 

    import android.app.Activity; 
    import android.content.Intent; 
    import android.media.MediaPlayer; 
    import android.os.Bundle; 

    public class Splash extends Activity { 

    MediaPlayer ourSong; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     ourSong = MediaPlayer.create(Splash.this, R.raw.happyman); 
     ourSong.start(); 
     Thread timer = new Thread(){ 
      public void run(){ 
       try{ 
        sleep(5000); 
       } catch (InterruptedException e){ 
        e.printStackTrace(); 
       }finally{ 
        Intent startMain = new Intent("com.example.secondapp.MENU"); 
        startActivity(startMain); 
       } 
      } 
     }; 
     timer.start(); 
    } 

    @Override 
    protected void onPause() { 
     // TODO Auto-generated method stub 
     super.onPause(); 
     finish(); 
    } 


} 

菜單

package com.example.secondapp; 


public class Menu extends ListActivity { 

String classes[] = {"MainActivity", "example1", "example2", "example3", "example4", "example5"}; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes)); 
} 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    // TODO Auto-generated method stub 
    String Cheese = classes[position]; 
    super.onListItemClick(l, v, position, id); 
    try{ 
    Class ourClass = Class.forName("com.example.secondapp." + Cheese); 
    Intent ourIntent = new Intent(Menu.this, ourClass); 
    startActivity(ourIntent); 
    }catch(ClassNotFoundException e){ 
     e.printStackTrace(); 
    } 
} 

} 

回答

1

您的清單中的行爲應該匹配。與com.example.secondapp.MENU

1

正是在帽改變它MENU應該Menu

更改爲

Intent startMain = new Intent("com.example.secondapp.Menu"); 

怎麼把你的活動是public class Menu extends ListActivity {和清單你必須

<activity 
     android:name=".Menu" 

編輯:

  1. 顯式意圖通過名稱(前面提到的 組件名稱字段具有值集)指定目標組件。由於其他 應用程序的開發人員通常不知道組件名稱,所以顯式意圖通常用於應用程序內部消息 - 例如啓動 下級服務或啓動姊妹活動的活動。

  2. 隱式意圖不會命名目標(組件 名稱的字段名稱爲空)。隱式意圖通常用於激活其他應用程序中的組件。

所以改爲明確意圖

Intent startMain = new Intent(Splash.this,Menu.class); // in Splash.java 

和清單

<activity 
     android:name="com.example.secondapp.Menu" 
     android:label="@string/app_name" > 
</activity> 

欲瞭解更多信息請檢查您需要設置ACTI的文檔

http://developer.android.com/guide/components/intents-filters.html

+0

更換

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

我想他正試圖定義啓動活動的訴訟。 – Blackbelt

+0

@blackbelt你是對的。也活動的名稱是菜單 – Raghunandan

+0

我認爲這是沒有必要的行動名稱完全匹配的活動名稱 – Blackbelt

0

在你的清單,你拼錯MENU VITY類

<activity 
      android:name=".MENU" 
      android:label="@string/app_name" > 
相關問題