I have an android app in which i am using google maps setting in the manifest.xml
file. 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
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
<?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"/>
So from the above i feel that everything was configured right but why i was still getting MainActivity class not found ?
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.
<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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.