FirebaseRecyclerAdapter's populateViewHolder() getting called before a key having certain values gets fully removed thus giving nullpointerexception

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:08:23

Well, I think I figured out a way.

Just placed some conditions in the code.

Here's the updated code:

    if (dataSnapshot.getValue() != null) {

         if (dataSnapshot.hasChild("pName") && dataSnapshot.hasChild("pUrl") && dataSnapshot.hasChild("cLat") && dataSnapshot.hasChild("cLng")) {

                 Map<String, String> map = (Map<String, String>) dataSnapshot.getValue();
                 pA = map.get("pName");
                 uA = map.get("pUrl");
                 String cLatS = map.get("cLat").trim();
                 currentLtAU = Double.parseDouble(cLatS);
                 String cLngS = map.get("cLng").trim();
                 currentLnAU = Double.parseDouble(cLngS);

                 viewHolder.setPName(pA);
                 viewHolder.setPUrl(uA);
                 viewHolder.setCurrentLatAU(String.valueOf(currentLtAU));
                 viewHolder.setCurrentLngAU(String.valueOf(currentLnAU));

          }
     }

and now everything works perfectly fine!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!