Reputation: 301
I've been trying to create what I would have imagined would be a rather simple application - on the start activity, there is a button to press and that will then launch a MapActivity displaying your current location.
However, whenever I press the button, I immediately a receive an error and am forced to quit the application.
Here's the log:
10-23 19:15:10.826: D/PhoneWindow(3227): DebugMonitor class=com.android.find.my.friends.MainActivity focus=true
10-23 19:15:19.496: D/AndroidRuntime(3227): Shutting down VM
10-23 19:15:19.496: W/dalvikvm(3227): threadid=3: thread exiting with uncaught exception (group=0x4001db88)
10-23 19:15:19.496: E/AndroidRuntime(3227): Uncaught handler: thread main exiting due to uncaught exception
10-23 19:15:19.506: E/AndroidRuntime(3227): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.find.my.friends/com.android.find.my.friends.ShowMap}: java.lang.NullPointerException
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2486)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.app.ActivityThread.access$2100(ActivityThread.java:123)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1843)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.os.Handler.dispatchMessage(Handler.java:99)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.os.Looper.loop(Looper.java:123)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.app.ActivityThread.main(ActivityThread.java:4321)
10-23 19:15:19.506: E/AndroidRuntime(3227): at java.lang.reflect.Method.invokeNative(Native Method)
10-23 19:15:19.506: E/AndroidRuntime(3227): at java.lang.reflect.Method.invoke(Method.java:521)
10-23 19:15:19.506: E/AndroidRuntime(3227): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
10-23 19:15:19.506: E/AndroidRuntime(3227): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
10-23 19:15:19.506: E/AndroidRuntime(3227): at dalvik.system.NativeStart.main(Native Method)
10-23 19:15:19.506: E/AndroidRuntime(3227): Caused by: java.lang.NullPointerException
10-23 19:15:19.506: E/AndroidRuntime(3227): at com.android.find.my.friends.ShowMap.onCreate(ShowMap.java:30)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
10-23 19:15:19.506: E/AndroidRuntime(3227): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2418)
10-23 19:15:19.506: E/AndroidRuntime(3227): ... 11 more
10-23 19:15:19.516: I/dalvikvm(3227): threadid=7: reacting to signal 3
10-23 19:15:19.546: I/dalvikvm(3227): Wrote stack trace to '/data/anr/traces.txt'
I am testing this on an HTC Tattoo running Android 1.6. I have also previously been able to create an app which displays just the MapActivity.
Any help guys?
[Edit]
Here's my onCreate method:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // bind the layout to the activity
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setStreetView(true);
mapController = mapView.getController();
mapController.setZoom(14); // Zoom 1 is world view
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new GeoUpdateHandler());
}
Upvotes: 0
Views: 443
Reputation: 9908
It appears that you have a NullPointerException
at line 30 in your ShowMap
class. If you could post your onCreate
method and line 30 I can help you figure out why.
Could you also paste the line that the exception happens on by itself? It is possible that findViewById
returns null, in which case your mapView
will be null. Make sure the layout that your MapView is defined in is the same layout that you pass into setContentView
.
Upvotes: 1