No Activity found to handle Intent when the manifest is correct

六眼飞鱼酱① 提交于 2019-12-25 02:09:35

问题


I have been going over this for an hour and I cannot figure out the issue. I am trying to launch a new activity when a boolean value is true inside the ACTION_UP TouchEvent.

public boolean onTouchEvent(MotionEvent event) {

            int eventaction = event.getAction();
            int X = (int)event.getX();
            int Y = (int)event.getY();
            fingerX = X;
            fingerY = Y;

            switch (eventaction ) {

            case MotionEvent.ACTION_DOWN:
                if (okayButton){
                    if (fingerX > 323 && fingerX < 423) {
                        largeOkayButton = true;
                    }
                }
                break;

            case MotionEvent.ACTION_MOVE:
                break;

            case MotionEvent.ACTION_UP:
                tutorial = true;
                if (startActivity){
                    //create an Intent variable titled openStartingPoint and pass its activity action from the Android Manifest.xml
                    Intent MainActivity = new Intent("com.example.shoottoiletpaper.MAINACTIVITY");
                    //start a new activity by passing the newly created Intent

                    startActivity(MainActivity);
                }
                break;
            }
        return true;
    }

Everything works until it gets to launching the activity, when it force closes and I get this in the logcat:

android.content.ActivityNotFoundException: No Activity found to handle Intent

Here's the relevant part of the manifest:

        <activity
        android:name="com.example.shoottoiletpaper.MainActivity"
        android:screenOrientation="landscape"
        android:configChanges="orientation|keyboard"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAINACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

Any ideas?


回答1:


Change this

Intent MainActivity = new Intent("com.example.shoottoiletpaper.MAINACTIVITY");

to

Intent MainActivity = new Intent("android.intent.action.MAINACTIVITY");



回答2:


Change

<action android:name="android.intent.action.MAINACTIVITY" />  

To

<action android:name="android.intent.action.MAIN" />



回答3:


What is your main activity's class name? If it isn't MAINACTIVITY, you've got yourself a typo.

Change

 Intent MainActivity = new Intent("com.example.shoottoiletpaper.MAINACTIVITY");

to

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

(or whatever your main activity is called). Case is important in Java.

And take a look at your manifest as well. (Look at the examples here.

You should change your line to read

 <action android:name="android.intent.action.MAIN"/>


来源:https://stackoverflow.com/questions/15514414/no-activity-found-to-handle-intent-when-the-manifest-is-correct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!