未找到启动器活动!在安卓中
Posted
技术标签:
【中文标题】未找到启动器活动!在安卓中【英文标题】:No Launcher Activity found ! in android 【发布时间】:2015-04-27 11:29:29 【问题描述】:我有一个 android 应用程序,我在其中使用 manifest.xml
文件中的谷歌地图设置。当我在 Eclipse 中运行应用程序时,输出如下所示
[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 ComponentInfocom.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_
android:layout_/>
所以从上面我觉得一切都配置正确,但为什么我仍然找不到 MainActivity 类?
【问题讨论】:
@NoName 是的,尝试使用点名和完整包名,但仍然出现相同的错误 你的意思是整个 MainActivity 代码? 可以添加 target-sdk 吗? 尝试更改软件包名称并重新安装。 @Droidekas 是的,添加并检查了它,但结果是一样的,真的无法弄清楚这里有什么问题 【参考方案1】:像这样修改这个:
<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>
只需提及该活动以及包名称即可
【讨论】:
【参考方案2】:只需在活动名称前添加一个点,即更改为 .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>
【讨论】:
【参考方案3】:<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>
像上面一样改变这个标签
【讨论】:
以上是关于未找到启动器活动!在安卓中的主要内容,如果未能解决你的问题,请参考以下文章
无法识别启动活动:升级到 Android Studio 4.0 后未找到默认活动