I'm having trouble on line 141, where it says the string is null and points me to the error in this line
JSONObject jsonObject = new JSONObject(response.body().toString());
But I am not able to solve, below the code along with logcat
:
try {
JSONObject jsonObject = new JSONObject(response.body().toString());
String lat = ((JSONArray)jsonObject.get("results"))
.getJSONObject(0)
.getJSONObject("geometria")
.getJSONObject("localizacao")
.get("lat").toString();
String lng = ((JSONArray)jsonObject.get("results"))
.getJSONObject(0)
.getJSONObject("geometria")
.getJSONObject("localizacao")
.get("lng").toString();
LatLng localizacaoPedido = new LatLng(Double.parseDouble(lat),Double.parseDouble(lng));
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.box);
bitmap = Comum.scaleBitmap(bitmap, 70, 70);
MarkerOptions marker = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.title("Pedido de "+Comum.pedidoAtual.getTelefone())
.position(localizacaoPedido);
mMap.addMarker(marker);
ERROR:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toString()' on a null object reference
at com.example.daniel.androidpadariaserver.RastreamentoPedido$1.onResponse(RastreamentoPedido.java:141)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)