Monday, November 18, 2013

Adding a marker results in NullPointerException in Android [android help]


Adding a marker results in NullPointerException in Android



This is a part of my project. I am getting an arraylist of longitude and latitude from the previous class. Without the marker code, the app is working properly but when I add the marker code the app is terminating due to NullpointerException. Can anyone tell me why ?



package xyz;

import...

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Route extends Activity {
GoogleMap map;
PolylineOptions polylineOptions;
ArrayList longitude,latitude;


@SuppressWarnings("unchecked")
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.route);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

double s_latitude = latitude.get(0);
double s_longitude=longitude.get(0);


/* If I add this line the app is terminating.
map.addMarker(new MarkerOptions()
.position(new LatLng(s_latitude,s_longitude))
.title("Start Point"));
*/

longitude = (ArrayList) getIntent().getSerializableExtra("Longitude");
latitude = (ArrayList) getIntent().getSerializableExtra("Latitude");

CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(latitude.get(0),
longitude.get(0)));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);

map.moveCamera(center);
map.animateCamera(zoom);



polylineOptions=new PolylineOptions();

for(int i=0;i {
polylineOptions.add(new LatLng(latitude.get(i), longitude.get(i)));
}

polylineOptions.color(Color.BLUE);
polylineOptions.width(10);

polylineOptions.geodesic(false);


map.addPolyline(polylineOptions);


}
}


11-10 21:15:14.027: E/AndroidRuntime(25929): FATAL EXCEPTION: main 11-10 21:15:14.027: E/AndroidRuntime(25929): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sensordatacollector.smartrac/com.sensordatacollector.smartrac.Route}: java.lang.NullPointerException 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2368) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.ActivityThread.access$600(ActivityThread.java:151) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1330) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.os.Handler.dispatchMessage(Handler.java:99) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.os.Looper.loop(Looper.java:155) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.ActivityThread.main(ActivityThread.java:5536) 11-10 21:15:14.027: E/AndroidRuntime(25929): at java.lang.reflect.Method.invokeNative(Native Method) 11-10 21:15:14.027: E/AndroidRuntime(25929): at java.lang.reflect.Method.invoke(Method.java:511) 11-10 21:15:14.027: E/AndroidRuntime(25929): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074) 11-10 21:15:14.027: E/AndroidRuntime(25929): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841) 11-10 21:15:14.027: E/AndroidRuntime(25929): at dalvik.system.NativeStart.main(Native Method) 11-10 21:15:14.027: E/AndroidRuntime(25929): Caused by: java.lang.NullPointerException 11-10 21:15:14.027: E/AndroidRuntime(25929): at com.sensordatacollector.smartrac.Route.onCreate(Route.java:36) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.Activity.performCreate(Activity.java:5066) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102) 11-10 21:15:14.027: E/AndroidRuntime(25929): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288) 11-10 21:15:14.027: E/AndroidRuntime(25929): ... 11 more



Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...