0

Hi Everyone I am using the code given here What is the simplest and most robust way to get the user's current location on Android? to get current location But I am getting the ClassNotFoundExecption Here is my complete code:

//MapActivity code:

package com.example.gmaps;
import com.example.gmaps.MyLocation.LocationResult;
import com.google.android.maps.MapActivity;
import android.location.Location;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends MapActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    LocationResult locationResult = new LocationResult(){
        @Override
        public void gotLocation(Location location){
            //Got the location!

            Toast.makeText(getApplicationContext(), "I got the location", Toast.LENGTH_LONG).show();
        }
    };
    MyLocation myLocation = new MyLocation();
    myLocation.getLocation(MainActivity.this, locationResult);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

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

}

ANd in MyLocation I have same code as given in above link Here is my logcat

> 10-18 16:49:51.222: E/AndroidRuntime(24816): FATAL EXCEPTION: main
10-18 16:49:51.222: E/AndroidRuntime(24816): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.gmaps/com.example.gmaps.MainActivity}: java.lang.ClassNotFoundException: com.example.gmaps.MainActivity
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.app.ActivityThread.access$600(ActivityThread.java:132)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.os.Looper.loop(Looper.java:137)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.app.ActivityThread.main(ActivityThread.java:4575)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at java.lang.reflect.Method.invokeNative(Native Method)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at java.lang.reflect.Method.invoke(Method.java:511)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at dalvik.system.NativeStart.main(Native Method)
10-18 16:49:51.222: E/AndroidRuntime(24816): Caused by: java.lang.ClassNotFoundException: com.example.gmaps.MainActivity
10-18 16:49:51.222: E/AndroidRuntime(24816):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
10-18 16:49:51.222: E/AndroidRuntime(24816):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1984)
10-18 16:49:51.222: E/AndroidRuntime(24816):    ... 11 more
Community
  • 1
  • 1
nadeem gc
  • 484
  • 1
  • 8
  • 22

2 Answers2

2

Did you add above code your AndroidManifest.xml ?

<uses-library android:name="com.google.android.maps" />

You must add this code between application tag.

yahya.can
  • 1,790
  • 1
  • 11
  • 9
  • yes i forgot to add this thanks a lot . BUt i am unable to get my current location. Exception is no more for that i am accepting your answer will you help me why i couldn't able to get my location? – nadeem gc Oct 18 '12 at 12:12
  • For this, i suggest you vogella website.( http://www.vogella.com/articles/AndroidLocationAPI/article.html at 4.3 ) Apply that to your project. Then you can get your location – yahya.can Oct 18 '12 at 12:59
1

Right click on Project and go to the properties -->> java build path..click on Libraries tab and click on Add External jar and select maps.jar from your computer...now go to order and export tab and tick checkbox of maps.jar ....Now...clean your project and run...

Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39