-1

i try of pass latitude like string from mysql to another method googlemaps this way:

Double bd_lat;
Double bd_lng;
protected void onCreate(Bundle savedInstanceState) {
    bd_lat = Double.parseDouble(object.getString("latitude"));
    bd_lng = Double.parseDouble(object.getString("longitude"));
}



@Override
    public void onMapReady(GoogleMap googleMap) {

LatLng Bello = new LatLng(bd_lat, bd_lng);

}

but it show me this error

  E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: com.elgeos.school, PID: 31026
                      java.lang.NullPointerException: Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference
                          at com.elgeos.school.MapsTracker.onMapReady(MapsTracker.java:149)

MapsTracker.java:149 is the next line:

LatLng Bello = new LatLng(bd_lat, bd_lng);

I dont know that i have bad, i'm noob in this

  • 2
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Gautam Chibde Jan 14 '18 at 06:10

2 Answers2

0

You are getting NULL Pointer Exception here in the code according to the error at this line :

new LatLng(bd_lat, bd_lng);

You need to check if the these object contains some values or not.

Moreover you can check the below link to check about the NPE here :

What is NPE and how to fix it?

Talib
  • 1,134
  • 5
  • 31
  • 58
0

It's because Double values are null, wrap it with null check

@Override
    public void onMapReady(GoogleMap googleMap) {
    if(bd_lat != null && bd_lng != null){
      LatLng Bello = new LatLng(bd_lat, bd_lng);
    }
}
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37