Click here to Skip to main content
15,908,834 members

Comments by sfdgasdfqqqq (Top 10 by date)

sfdgasdfqqqq 20-Mar-19 12:36pm View    
Intent toMap = new Intent(context,MapActivity.class);
Bundle coords = new Bundle();
coords.putDouble("lat",lcoords);
coords.putDouble("lon",lcoords2);
context.startActivity(toMap);

This is my Bundle, coords.
sfdgasdfqqqq 20-Mar-19 12:11pm View    
if I am going to use getExtras(), the getDOuble on this code produces a null pointer exception.

double lat1 = coords.getDouble("lat");
sfdgasdfqqqq 20-Mar-19 11:40am View    
I am passing a Double data type. I inserted this code:

Intent toMap = new Intent(context,MapActivity.class);
Bundle coords = new Bundle();
coords.putDouble("lat",lcoords);
coords.putDouble("lon",lcoords2);
toMap.putExtras(coords);
context.startActivity(toMap);

System.out.print(coords);

lcoords contains the latitude. lcoords2 contains the longitude. Whenever I access the Bundle to my MapActivity.class, it says "getDouble on a null object reference"

Bundle coords = getIntent().getBundleExtra("coords");
double lat1 = coords.getDouble("lat");
double lon2 = coords.getDouble("lon");

LatLng location = new LatLng(lat1,lon2);
marker = mMap.addMarker(new MarkerOptions()
.position(location)
.title("Here")
.flat(true));

mMap.moveCamera(CameraUpdateFactory.newLatLng(location));


If I comment out those codes, lcoords and lcoords2 have values and is not null.
sfdgasdfqqqq 20-Mar-19 10:41am View    
Also, I tried using Intent but it says, cannot resolve constructor. Maybe because, SmsReceiver is only a class, not an activity itself.
sfdgasdfqqqq 20-Mar-19 10:31am View    
Hello. This is what I have tried but I am getting a NullObjectReference error on my LatLng.

HashMap <string, double=""> hashMap = smsReceiver.getLocMap(coordinates);
if(hashMap != null) {
// Double lat = hashMap.get("latitude");
// Double lon = hashMap.get("longitude");


LatLng location = new LatLng(coordinates.get("latitude"),coordinates.get("longitude"));
marker = mMap.addMarker(new MarkerOptions()
.position(location)
.title("Here")
.flat(true));

mMap.moveCamera(CameraUpdateFactory.newLatLng(location));

This is my a class with my hashmap.
//variable
private HashMap<string, double=""> coordinates = new HashMap<string, double="">();

public void sendDataToFirebase(SmsMessage sms, Context context) {
coordinates.put("latitude", latitudedb);
coordinates.put("longitude", longitudedb);
mRef.setValue(coordinates);

Double lcoords = coordinates.get("latitude");
Double lcoords2 = coordinates.get("longitude");




mRef.getKey();

System.out.println(lcoords);
System.out.println(lcoords2);

// }

}

public HashMap<string, double=""> getLocMap(HashMap<string, double=""> coordinates) {
return this.coordinates;

}

When I print out my coordinates, it has the values.