I want to mark a location on a new map in a new activity. This is my code.
Ive sent my coordinates with putExtra
Intent intent = new Intent(this, RealMap.class);
Bundle args = new Bundle();
args.putDouble("latitude",honey.latitude);
args.putDouble("longitude",honey.longitude);
intent.putExtra("bundle",args);
startActivity(intent);
Intent i = new Intent(getApplicationContext(),ShowHoney.class);
startActivity(i);
And I received them like this
double lat = 0;
double lon = 0;
Bundle bundle = getIntent().getParcelableExtra("bundle");
if (bundle != null) {
lat = bundle.getParcelable("latitude");
lon = bundle.getParcelable("longitude");
LatLng honey = new LatLng(lat, lon);
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.mipmap.mylocation);
}
This isn't the full code I don't think there's a problem elsewhere. My code doesn't have problem compiling but when I try it on my phone it shuts down. It says the bundle is a null pointer. I don't know why it won't work.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Parcelable android.os.Bundle.getParcelable(java.lang.String)' on a null object reference
So I tried putting in if(bundle!=null) The app works, but it doesn't do what I really want it to, because the bundle is always null