【问题标题】:Android: Activity not found to handle intentAndroid:未找到处理意图的活动
【发布时间】:2013-11-04 11:09:58
【问题描述】:

我在运行程序时收到此错误。它启动了第一页,但是当它应该转到 .Menu 时它崩溃了:

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 活动和我的 .Menu 活动的 .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();
    }
}

 }

【问题讨论】:

    标签: java android eclipse android-activity


    【解决方案1】:

    在您的清单中,动作应该匹配。改成com.example.secondapp.MENU

    【讨论】:

      【解决方案2】:

      大写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>
      

      有关更多信息,请查看文档

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

      【讨论】:

      • 我认为他正在尝试定义启动该活动的操作。
      • 我认为动作名称没有必要与活动名称完全匹配
      • @blackbelt 是的,关于意图过滤器 developer.android.com/guide/components/intents-filters.html 中的操作名称,您再次正确。
      • 我之前尝试过明确表示但没有奏效。现在它确实如此,所以一定是一个错字。谢谢!
      • @JurjenvanGenugten 是的,这是一个拼写错误。如果你做得对,让它明确会起作用检查文档
      【解决方案3】:

      您需要在清单中设置活动类别,但您拼错了 MENU

      替换

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-15
        • 1970-01-01
        • 1970-01-01
        • 2013-08-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多