Android FATAL EXCEPTION ActivityNotFoundException

时间:2014-02-02 11:50:46

标签: android eclipse

首先,我使用的是Eclipse IDE。我试图建立一个应用程序商店。我不知道发生了什么,但之前有效,现在我在LogCat中收到了这个错误。

02-02 13:26:39.750: E/AndroidRuntime(280): FATAL EXCEPTION: main
02-02 13:26:39.750: E/AndroidRuntime(280): android.content.ActivityNotFoundException: No               Activity found to handle Intent { act=com.example.appstore.GAMENAME }
02-02 13:26:39.750: E/AndroidRuntime(280):  at     android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.app.Activity.startActivityForResult(Activity.java:2817)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.app.Activity.startActivity(Activity.java:2923)
02-02 13:26:39.750: E/AndroidRuntime(280):  at com.servetech.appstore.MainActivity$1.onClick(MainActivity.java:28)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.view.View.performClick(View.java:2408)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.view.View$PerformClick.run(View.java:8816)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.os.Handler.handleCallback(Handler.java:587)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-02 13:26:39.750: E/AndroidRuntime(280):  at android.os.Looper.loop(Looper.java:123)
02-02 13:26:39.750: E/AndroidRuntime(280):  at     android.app.ActivityThread.main(ActivityThread.java:4627)
02-02 13:26:39.750: E/AndroidRuntime(280):  at java.lang.reflect.Method.invokeNative(Native Method)
02-02 13:26:39.750: E/AndroidRuntime(280):  at         java.lang.reflect.Method.invoke(Method.java:521)
02-02 13:26:39.750: E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-02 13:26:39.750: E/AndroidRuntime(280):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-02 13:26:39.750: E/AndroidRuntime(280):  at dalvik.system.NativeStart.main(Native Method)

MainActivity.java

package com.servetech.appstore;


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {


Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn = (Button) findViewById(R.id.button1);

    btn.setOnClickListener(
            new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent myIntent = new Intent("com.example.appstore.GAMENAME");
                    startActivity(myIntent);
                }
            });

}



}

Android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.servetech.appstore"
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.servetech.appstore.MainActivity"
        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=".GameName"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.servetech.appstore.GAMENAME" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

</application>

PS:我注意到我的启动活动有点不同于其他人。只是为了让你知道我正在学习新浪博士的教程。我希望这不是问题。如果需要,我可以发布GameName类。

编辑:已经解决了这个问题,所以不要浪费你的时间来帮助:)

3 个答案:

答案 0 :(得分:1)

您尝试运行课程"com.example.appstore.GAMENAME,但在清单中您获得了packageName+.GameName。 因此,而不是Intent myIntent = new Intent("com.example.appstore.GAMENAME");尝试Intent myIntent = new Intent("com.servetech.appstore.GAMENAME");

答案 1 :(得分:1)

将活动中的意图更改为:

 Intent myIntent = new Intent("com.servetech.appstore.GAMENAME");

答案 2 :(得分:0)

GAMENAME的真正包裹是com.servetech.appstore.GAMENAME而不是com.example.appstore.GAMENAME。这就是Android无法找到活动的原因。

  

android.content。 ActivityNotFound 异常:未找到任何活动来处理意图

所以

Intent myIntent = new Intent("com.example.appstore.GAMENAME");

Intent myIntent = new Intent("com.servetech.appstore.GAMENAME");