Jurjen van Genugten
Jurjen van Genugten

Reputation: 121

Android: Activity not found to handle intent

I get this error when I run my program. It starts up the first page, but when it's supposed to go to .Menu it crashes:

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)

Here's my Manifest:

    <?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>

And here are the .java files of my .Splash activity and my .Menu activity:

Splash

    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();
    }


}

Menu

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();
    }
}

 }

Upvotes: 2

Views: 4492

Answers (3)

You need to set activity class in your manifest and you misspelled MENU

replace

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

with

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

Upvotes: 0

Raghunandan
Raghunandan

Reputation: 133580

It is in caps MENU should be Menu

Change to

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

coz your activity is public class Menu extends ListActivity { and in manifest you have

  <activity
        android:name=".Menu"

Edit:

  1. Explicit intents designate the target component by its name (the component name field, mentioned earlier, has a value set). Since component names would generally not be known to developers of other applications, explicit intents are typically used for application-internal messages — such as an activity starting a subordinate service or launching a sister activity.

  2. Implicit intents do not name a target (the field for the component name is blank). Implicit intents are often used to activate components in other applications.

So Change to explicit intent

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

and in manifest

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

For more info check the docs

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

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157487

in your manifest the action should match. Change it with com.example.secondapp.MENU

Upvotes: 1

Related Questions