4

I'm working with Google Maps v2 and I want to determine my location. I work with Genymotion emulator. I need to activate GPS on my test device. If I'm testing on the emulator and it's not activated "null" if I'm trying to use a LocationManager. I'm using the "DDMS" Perspective of Eclipse to send geoposition to the emulator. Window → Open Perspective → Other... → DDMS.But all fields are not clickable.

I did how Breadbin said,but i still have null pointer exception enter image description here

`

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    map=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
    map.setMyLocationEnabled(true);
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    String provider =  locationManager.getBestProvider(criteria, true);
    Location myLocation = locationManager.getLastKnownLocation(provider);
    map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
    double latitude = myLocation.getLatitude();
    double longitude = myLocation.getLongitude();
    LatLng latLng = new LatLng(latitude, longitude);
    map.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    map.animateCamera(CameraUpdateFactory.zoomTo(20));
    map.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here"));
    }`
11-20 04:28:48.056: D/dalvikvm(1645): GC_FOR_ALLOC freed 226K, 2% free 16823K/17076K, paused 7ms, total 7ms
11-20 04:28:48.332: D/dalvikvm(1645): GC_FOR_ALLOC freed 309K, 2% free 17029K/17364K, paused 7ms, total 7ms
11-20 04:28:48.412: D/dalvikvm(1645): GC_FOR_ALLOC freed 260K, 2% free 17282K/17568K, paused 6ms, total 6ms
11-20 04:28:48.496: D/dalvikvm(1645): GC_FOR_ALLOC freed 109K, 2% free 17546K/17784K, paused 10ms, total 10ms
11-20 04:28:48.540: D/dalvikvm(1645): GC_FOR_ALLOC freed 28K, 1% free 17906K/18084K, paused 6ms, total 6ms
11-20 04:28:48.540: D/AndroidRuntime(1645): Shutting down VM
11-20 04:28:48.540: W/dalvikvm(1645): threadid=1: thread exiting with uncaught exception (group=0xa4c49648)
11-20 04:28:48.544: E/AndroidRuntime(1645): FATAL EXCEPTION: main
11-20 04:28:48.544: E/AndroidRuntime(1645): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.Mymaps/com.example.Mymaps.MainActivity}: java.lang.NullPointerException
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.os.Looper.loop(Looper.java:137)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.ActivityThread.main(ActivityThread.java:5103)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at java.lang.reflect.Method.invokeNative(Native Method)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at java.lang.reflect.Method.invoke(Method.java:525)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at dalvik.system.NativeStart.main(Native Method)
11-20 04:28:48.544: E/AndroidRuntime(1645): Caused by: java.lang.NullPointerException
11-20 04:28:48.544: E/AndroidRuntime(1645):     at com.example.Mymaps.MainActivity.onCreate(MainActivity.java:33)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.Activity.performCreate(Activity.java:5133)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-20 04:28:48.544: E/AndroidRuntime(1645):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
11-20 04:28:48.544: E/AndroidRuntime(1645):     ... 11 more
11-20 04:28:48.840: W/ActivityThread(1645): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
11-20 04:45:28.501: W/ActivityThread(3967): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader());
user3009926
  • 41
  • 1
  • 4

2 Answers2

2

If you are using genymotion you set the mock location with genymotion. I.e. theres a button on the side of the emulator where you turn GPS on and set accuracy and mock location on a map

Breadbin
  • 410
  • 4
  • 15
-1

Make sure that the device is selected in the Devices view. You cannot use Emulator Control unless the device or emulator is selected.

If it doesn't work, then close Eclipse,there's a ddms shell script in the tools/ directory of wherever you installed the Android SDK.

If still it doesn't work, run adb kill-server, followed by adb start-server, where adb should be in your platform-tools/ directory of your SDK installation. Then, try DDMS again.

If that does not help, reboot, then try DDMS again.

CodeWarrior
  • 5,026
  • 6
  • 30
  • 46