简体   繁体   English

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

[英]No Launcher Activity found ! in android

I have an android app in which i am using google maps setting in the manifest.xml file. 我有一个Android应用程序,我在manifest.xml文件中使用谷歌地图设置。 When i run the app in the eclipse the output was as below 当我在日食中运行应用程序时,输出如下

[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!

The app was installed on the emulator(android 4.2.2, API level 19) but when i tried to open it the was crashed by saying Unfortunately your app was closed and i found the below error in logcat 该应用程序安装在模拟器上(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

Below are the code files 以下是代码文件

AndroidManifest.xml 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 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 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"/>

So from the above i feel that everything was configured right but why i was still getting MainActivity class not found ? 所以从上面我觉得一切都配置正确,但为什么我仍然没有找到MainActivity类?

modify this one like: 修改这个像:

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

to

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

just mention that activity along with package name 只需提及该活动以及包名称

Just add a dot before name of activity ie change to .MainActivity instead of Activity because android is unable to find it after relating to the package name. 只需在活动名称之前添加一个点,即更改为.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>
<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>

change this tag as above 如上所述更改此标记

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM