There is a stream in which additional markers and their subsequent update occur.

timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { MapsActivity.this.runOnUiThread(new Runnable() { @Override public void run() { /* if (var!=null) { if (fullDrivers.size() >= 1) { for (int i = 0; i < fullDrivers.size(); i++) { finalMarker[i].setPosition(transfomation(fullDrivers.get(i).getLatlng())); } } }else { for (int i = 0; i < fullDrivers.size(); i++) { finalMarker[i] = mMap.addMarker(new MarkerOptions().position(transfomation(fullDrivers.get(i).getLatlng()))); var="+++"; } }*/ if (icount!=0){ for (int i = 0; i < fullDrivers.size(); i++){ finalMarker[i].setPosition(transfomation(fullDrivers.get(i).getLatlng())); Log.d(TAG,"Obnovlenie prowlo Udacno!"); } }else{ for (int i = 0; i < fullDrivers.size(); i++) { finalMarker[i] = mMap.addMarker(new MarkerOptions().position(transfomation(fullDrivers.get(i).getLatlng()))); icount++; Log.d(TAG,"Pervoe Dobavlenie markerov prowlo Udacno !"); } } //------------------------------------- } }); /* }*/ } },0,6000); 

With the addition of problems there is no. But when updating, it crashes with an error

 > 05-12 00:33:30.541 9613-9613/xyz.justart.getallandposition > E/AndroidRuntime: FATAL EXCEPTION: main > Process: xyz.justart.getallandposition, PID: 9613 > java.lang.NullPointerException: Attempt to invoke virtual method 'void > com.google.android.gms.maps.model.Marker.setPosition(com.google.android.gms.maps.model.LatLng)' > on a null object reference > at > xyz.justart.getallandposition.MapsActivity$2$1.run(MapsActivity.java:133) > at android.os.Handler.handleCallback(Handler.java:739) > at android.os.Handler.dispatchMessage(Handler.java:95) > at android.os.Looper.loop(Looper.java:148) > at android.app.ActivityThread.main(ActivityThread.java:7325) > at java.lang.reflect.Method.invoke(Native Method) > at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) > at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
  • 3
    finalMarker[i] == null . - post_zeew
  • @post_zeew did not understand. They couldn’t show where the error is ??? I’m trying not to succeed. - elik
  • Isn’t java.lang.NullPointerException saying anything? habrahabr.ru/post/221243 - Sergey

1 answer 1

If you look at the code from your previous question , I will assume that you initialized an array with markers with a given size, but did not fill it with markers. It turns out that all the elements of the array are null , your block of code with if (icount!=0) does not have time to get into the direction where they are initialized, but it gets into that direction when they call methods and when you try to call methods with null , you certainly get a NullPointerException .