Reputation: 21
Everytime I try to run my app I get this error:
unfortunately, has stopped
Source:
package com.example.mapsapp;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import android.os.Bundle;
import android.view.Menu;
public class HichRideActivity extends MapActivity
{
MapController mControl;
GeoPoint geop;
MapView mapV;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hich_ride);
mapV= (MapView) findViewById(R.id.menu_settings);
mapV.displayZoomControls(true);
mapV.setBuiltInZoomControls(true);
double lat= 40.8;
double longi=-96.666;
geop = new GeoPoint ((int)(lat * 1E6), (int)(longi * 1E6));
mControl.animateTo(geop);
mControl.setZoom(13);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_hich_ride, menu);
return true;
}
@Override
protected boolean isRouteDisplayed()
{
// TODO Auto-generated method stub
return false;
}
}
And here is logcat, it says that I have NullPointerException
's but I don't know which parameter is null
.
logcat:
07-31 13:40:46.344: E/Trace(1043): error opening trace file: No such file or directory (2) 07-31 13:40:47.134: D/AndroidRuntime(1043): Shutting down VM 07-31 13:40:47.134: W/dalvikvm(1043): threadid=1: thread exiting with uncaught exception (group=0x40a13300) 07-31 13:40:47.194: D/dalvikvm(1043): GC_CONCURRENT freed 195K, 3% free 8273K/8519K, paused 80ms+5ms, total 166ms 07-31 13:40:47.194: D/dalvikvm(1043): WAIT_FOR_CONCURRENT_GC blocked 26ms 07-31 13:40:47.194: E/AndroidRuntime(1043): FATAL EXCEPTION: main 07-31 13:40:47.194: E/AndroidRuntime(1043): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapsapp/com.example.mapsapp.HichRideActivity}: java.lang.NullPointerException 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.ActivityThread.access$600(ActivityThread.java:130) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.os.Handler.dispatchMessage(Handler.java:99) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.os.Looper.loop(Looper.java:137) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.ActivityThread.main(ActivityThread.java:4745) 07-31 13:40:47.194: E/AndroidRuntime(1043): at java.lang.reflect.Method.invokeNative(Native Method) 07-31 13:40:47.194: E/AndroidRuntime(1043): at java.lang.reflect.Method.invoke(Method.java:511) 07-31 13:40:47.194: E/AndroidRuntime(1043): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 07-31 13:40:47.194: E/AndroidRuntime(1043): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 07-31 13:40:47.194: E/AndroidRuntime(1043): at dalvik.system.NativeStart.main(Native Method) 07-31 13:40:47.194: E/AndroidRuntime(1043): Caused by: java.lang.NullPointerException 07-31 13:40:47.194: E/AndroidRuntime(1043): at com.example.mapsapp.HichRideActivity.onCreate(HichRideActivity.java:27) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.Activity.performCreate(Activity.java:5008) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 07-31 13:40:47.194: E/AndroidRuntime(1043): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 07-31 13:40:47.194: E/AndroidRuntime(1043): ... 11 more 07-31 13:40:47.214: W/CursorWrapperInner(1043): Cursor finalized without prior close() 07-31 13:40:47.214: W/CursorWrapperInner(1043): Cursor finalized without prior close()
Upvotes: 0
Views: 1076
Reputation: 414
These lines: mControl.animateTo(geop);
mControl.setZoom(13);
are your problem. You're using a MapController
that hasn't been created yet, you declared it at the top of your class, but you never instantiated it - So, after you declare your MapView
, add this line : mControl = mapV.getController();
. Try that and let me know if it works!
Upvotes: 0
Reputation: 15847
mapV= (MapView) findViewById(R.id.menu_settings);
^^^^^^^^^^^^^
this should be ID of MapView
and it should declare in activity_hich_ride.xml
Upvotes: 1