找不到启动器活动!在android中

时间:2015-02-25 12:53:19

标签: android eclipse android-activity android-fragments android-launcher

我有一个Android应用程序,我在manifest.xml文件中使用谷歌地图设置。当我在日食中运行应用程序时输出如下

[2015-02-25 17:59:06 - MainActivity] ------------------------------
[2015-02-25 17:59:06 - MainActivity] Android Launch!
[2015-02-25 17:59:06 - MainActivity] adb is running normally.
[2015-02-25 17:59:06 - MainActivity] No Launcher activity found!
[2015-02-25 17:59:06 - MainActivity] The launch will only sync the application package on the device!
[2015-02-25 17:59:06 - MainActivity] Performing sync
[2015-02-25 17:59:06 - MainActivity] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Nexus7'
[2015-02-25 17:59:06 - MainActivity] Uploading MainActivity.apk onto device 'emulator-5554'
[2015-02-25 17:59:07 - MainActivity] Installing MainActivity.apk...
[2015-02-25 17:59:19 - MainActivity] Success!
[2015-02-25 17:59:19 - appcompat_v7] Could not find appcompat_v7.apk!
[2015-02-25 17:59:19 - MainActivity] /MainActivity/bin/MainActivity.apk installed on device
[2015-02-25 17:59:19 - MainActivity] Done!

应用程序安装在模拟器上(android 4.2.2,API级别19),但是当我试图打开它时,通过说Unfortunately your app was closed而崩溃,我在logcat中发现了以下错误

02-25 07:37:30.540: E/AndroidRuntime(2194): FATAL EXCEPTION: main
02-25 07:37:30.540: E/AndroidRuntime(2194): Process: com.example.project, PID: 2194
02-25 07:37:30.540: E/AndroidRuntime(2194): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.project/com.example.project.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.project.MainActivity" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.project-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.project-1, /vendor/lib, /system/lib]]
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.os.Handler.dispatchMessage(Handler.java:102)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.os.Looper.loop(Looper.java:136)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at java.lang.reflect.Method.invoke(Method.java:515)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at dalvik.system.NativeStart.main(Native Method)
02-25 07:37:30.540: E/AndroidRuntime(2194): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.project.MainActivity" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.project-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.project-1, /vendor/lib, /system/lib]]
02-25 07:37:30.540: E/AndroidRuntime(2194):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
02-25 07:37:30.540: E/AndroidRuntime(2194):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
02-25 07:37:30.540: E/AndroidRuntime(2194):     ... 11 more
02-25 07:37:36.350: I/Process(2194): Sending signal. PID: 2194 SIG: 9

以下是代码文件

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.project"
          android:versionCode="12"
          android:versionName="1.1.9">
    <uses-sdk android:minSdkVersion="16"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="com.example.project.permission.C2D_MESSAGE" />
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:theme="@style/LightTheme">
        <meta-data android:name="com.google.android.gms.version" android:value="5077000" />
        <uses-library android:name="com.google.android.maps" />
        <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="xxxxxxxxxxxxxxxxxxxxxx" />
        <receiver android:name="com.example.project.MessageReceiver" android:exported="true"
                  android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.example.project" />
            </intent-filter>
        </receiver>
        <activity android:name="MainActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </activity>
    </application>
</manifest>

MainActivity.java

package com.example.project;


import android.app.*
.......

public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
    SwipeFragmentAdapter mAppSectionsPagerAdapter;
    ViewPager mViewPager;

    ....
    ....

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.main);

        mAppSectionsPagerAdapter = new SwipeFragmentAdapter(getSupportFragmentManager());
        mAppSectionsPagerAdapter.delegate = this;
        credentials = this.getPreferences(Context.MODE_PRIVATE);
        if (credentials.getString("email", null) == null || credentials.getString("group", null) == null) {
            userValid(false);
        } else {
            validateUser();
        }
    }

    .......
    .......

main.xml中

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
                                   android:id="@+id/pager"
                                   android:layout_width="match_parent"
                                   android:layout_height="match_parent"/>

所以从上面我觉得一切都配置正确,但为什么我仍然没有找到MainActivity类?

3 个答案:

答案 0 :(得分:0)

修改这个,如:

<activity android:name="MainActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </activity>

<activity android:name="com.example.project.MainActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </activity>

只需提及该活动以及包名称

答案 1 :(得分:0)

只需在活动名称前添加一个点,即更改为.MainActivity而不是Activity,因为android在与包名相关后无法找到它。

<activity android:name=".MainActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </activity>

答案 2 :(得分:0)

<activity android:name="com.example.project.MainActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </activity>

按上述方式更改此标记