首先,我正在使用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:我注意到我开始活动与其他人有所不同。只是为了让您知道我正在从newboston教程中学习。我希望这不是问题。如果需要,我可以发布GameName类。

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

最佳答案

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


  android.content.ActivityNotFound异常:找不到用于处理Intent的活动


所以

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




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

08-17 20:49