2

I am trying to create an application location, but it shows me the error the application of gmaps (com.formation.gmaps) has stopped unexpectedly.

Note that I have already uninstalled eclipse but always this error appears.

Here is my Error log:

03-25 14:21:59.914: E/AndroidRuntime(431): FATAL EXCEPTION: main
03-25 14:21:59.914: E/AndroidRuntime(431): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.formation.gmaps/com.formation.gmaps.MainActivity}: java.lang.ClassNotFoundException: com.formation.gmaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.formation.gmaps-1.apk]
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.os.Looper.loop(Looper.java:123)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.app.ActivityThread.main(ActivityThread.java:4627)
03-25 14:21:59.914: E/AndroidRuntime(431):  at java.lang.reflect.Method.invokeNative(Native Method)
03-25 14:21:59.914: E/AndroidRuntime(431):  at java.lang.reflect.Method.invoke(Method.java:521)
03-25 14:21:59.914: E/AndroidRuntime(431):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-25 14:21:59.914: E/AndroidRuntime(431):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-25 14:21:59.914: E/AndroidRuntime(431):  at dalvik.system.NativeStart.main(Native Method)
03-25 14:21:59.914: E/AndroidRuntime(431): Caused by: java.lang.ClassNotFoundException: com.formation.gmaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.formation.gmaps-1.apk]
03-25 14:21:59.914: E/AndroidRuntime(431):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
03-25 14:21:59.914: E/AndroidRuntime(431):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
03-25 14:21:59.914: E/AndroidRuntime(431):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
03-25 14:21:59.914: E/AndroidRuntime(431):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
03-25 14:21:59.914: E/AndroidRuntime(431):  ... 11 more

This is MainActivity.java

package com.formation.gmaps;

import android.os.Bundle;
import android.view.Menu;

import com.google.android.maps.MapActivity;

public class MainActivity extends MapActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }

}

This is AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.formation.gmaps.MainActivity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_GPS"/>
    <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.formation.gmaps.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>
    </application>

</manifest>
midhunhk
  • 5,560
  • 7
  • 52
  • 83
user2207848
  • 47
  • 3
  • 9

1 Answers1

1

The system cannot find the MainActivity.class in your com.formation.gmaps package. This can be caused by many things but you can check if:

1. You declared your activity com.formation.gmaps.MainActivity in your AndroidManifest.xml.

2. Your MainActivity.java has the correct package name set in the top of the file (e.g package com.formation.gmaps).

3. You should have import com.formation.gmaps.R;

4. Use the shortcut CTRL + SHIFT + O in Eclipse. This will import any missing classes.

5. A Project -> Clean could also help(provided you're using Eclipse).


EDIT

In your AndroidManifest.xml change package="com.formation.gmaps.MainActivity" to package="com.formation.gmaps".


EDIT 02

Your problem is your MapActivity.java. Read this. If you used the latest API then this paragraph explains it:

Because maps are encapsulated in the MapFragment class, you can implement them by extending the Android standard Activity class, rather than extending the MapActivity used in version 1.

So please check your MapActivity.class. If it extends Fragment then the problem is there. You can test this by changing your MainActivity to extent Activity instead of MapActivity. Do not forget to add import android.app.Activity;

If you're still using V1 of Maps then read the documentation on the link I have provided and switch to V2. You might still be using the old version which requires the process of importing a maps.jar.

This might help you as well.

Good luck and let us know if you run into more trouble.

Community
  • 1
  • 1
sebster
  • 1,322
  • 2
  • 18
  • 29
  • I have edited my answer. Please check number 3 on the list. You have to import your R.java, otherwise you will not have access to the resources you have declared throughout your project. Let me know if it works. – sebster Mar 25 '13 at 21:15
  • you still get the same error?.. can you post your AndroidManifest.xml? – sebster Mar 25 '13 at 21:55
  • aha... your package="com.formation.gmaps.MainActivity" should be package="com.formation.gmaps". Change that and run the code again. Also change the android:targetSdkVersion="8" to android:targetSdkVersion="17". – sebster Mar 25 '13 at 22:03
  • did you perform a Project -> Clean after all the changes?.. Also try deleting your R.java from gen/ then perform a Project -> Clean afterwards. Restarting Eclipse could also be of help. – sebster Mar 25 '13 at 22:14
  • Check my edit on the answer. And keep calm and carry on :) What can I say... Welcome to Development! – sebster Mar 25 '13 at 22:40
  • yes it s developement !! i will try it and tell you if it works; thanks again – user2207848 Mar 25 '13 at 22:48
  • I have added some more resources in my answer. Please check them. – sebster Mar 25 '13 at 23:08
  • Glad to hear that... you might want to accept the answer so others might learn from this. Or add additional details in your question. Up to you. – sebster Mar 26 '13 at 10:27
  • finally it works. I added **** in AndroidManifest.xml. thanks a lot for your help – user2207848 Mar 26 '13 at 11:02