cannot retrieve data from firebase to show users in fields for modification, java.lang.NullPointerException in android Java
<p>When I want to retrieve data from FirebaseDatabase for showing them to users,  allowing them to modify their inputs.</p>

<p>I get java.lang.NullPointerException errors as followings:</p>

<p>It's strange. Even I checked the firebaseDatabse, the inputs already are there under each use's unique ID.</p>

<p>Please help me to solve this problem, and tell me the reason why.
Your kindly help are highly appreciated.</p>

<pre><code>FATAL EXCEPTION: main
Process: com.comli.loyalfine.myfirstgooglemapapplication, PID:16262 java.lang.NullPointerException 
at com.comli.loyalfine.myfirstgooglemapapplication.ParkingSpaceRegisterActivity$12.onDataChange(ParkingSpaceRegisterActivity.java:495)
at com.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:56)
at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Following are my codes</p>

<pre><code>public void ReadAndDisplayData() {
    mDatabaseRef= FirebaseDatabase.getInstance().getReference();
    mDatabaseRef.child("Parking Space Data").child("Not Verified").child(userId).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            ParkingSpaceData post = null;

            post = dataSnapshot.getValue(ParkingSpaceData.class);
            assert post != null;
            System.out.print("etParkingSpaceAddress is "+post.getParkingAddress().toString());
            System.out.print("etLatLgn is "+post.getLatlng().toString());
            System.out.print("entranceuri is "+post.getIvParkingSpaceEntranceUri().toString());

            StorageReference fileRef = storageRef.child(userId).child("image").child(post.getEntranceRef());
            System.out.print("file uri is " +fileRef.getDownloadUrl().toString());
            ivParkingSpaceEntranceUri = post.getIvParkingSpaceEntranceUri();
            ivCertificateOfOwnershipUri = post.getIvCertificateOfOwnershipUri();
            vvVideoOfEntranceToParkingSpaceUri = post.getVvVideoOfEntranceToParkingSpaceUri();

            //Toast.makeText(ParkingSpaceRegisterActivity.this,"entranceuri is "+post.getIvParkingSpaceEntranceUri().toString(), Toast.LENGTH_LONG).show();
            // Toast.makeText(ParkingSpaceRegisterActivity.this,"file uri is " +fileRef.getDownloadUrl().toString(),Toast.LENGTH_LONG).show();
            //Picasso.with(ParkingSpaceRegisterActivity.this).load(ivParkingSpaceEntranceUri).fit().centerCrop().into(ivParkingSpaceEntrance);
            assert fileRef != null;
            fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener&lt;Uri&gt;() {
                @Override
                public void onSuccess(Uri uri) {
                    Picasso.with(ParkingSpaceRegisterActivity.this).load(uri).fit().centerCrop().into(ivParkingSpaceEntrance);
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle any errors
                }
            });
            fileRef = storageRef.child(userId).child("image").child(post.getOwnershipRef());
            fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener&lt;Uri&gt;() {
                @Override
                public void onSuccess(Uri uri) {
                    Picasso.with(ParkingSpaceRegisterActivity.this).load(uri).fit().centerCrop().into(ivCertificateOfOwnership);
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle any errors
                }
            });
            fileRef = storageRef.child(userId).child("video").child(post.getVideoRef());
            fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener&lt;Uri&gt;() {
                @Override
                public void onSuccess(Uri uri) {
                    vvVideoOfEntranceToParkingSpace.setBackgroundResource(0);
                    vvVideoOfEntranceToParkingSpace.setVideoURI(uri);
                    vvVideoOfEntranceToParkingSpace.start();
                    vvVideoOfEntranceToParkingSpace.pause();
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle any errors
                }
            });
            etParkingSpaceAddress.setText(post.getParkingAddress(), TextView.BufferType.EDITABLE);
            etLatLgn.setText(post.getLatlng(), TextView.BufferType.EDITABLE);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            // Getting Post failed, log a message
            Toast.makeText(ParkingSpaceRegisterActivity.this, "loadPost:onCancelled" + databaseError.toException().getMessage(), Toast.LENGTH_LONG).show();
            // ...
        }
    });
}
</code></pre>

<p>The data structure listed in FirebaseDataBase as folloiwngs:</p>

<pre><code>{"ParkingSpace" : 
   {"Not Verified" : 
     {"0vmf1Xc2M2SOYIyFCQz0YFouVH43" :  
       {"entranceRef" : "ivParkingSpaceEntrance.jpg",
        "latlng" : "lat/lng: (25.02859848016432,121.51109274476765)",
        "myMarkerPosition" : 
         {"latitude" : 25.02859848016432,
          "longitude" : 121.51109274476765},
        "ownershipRef" : "ivCertificateOfOwnership.jpg",
        "parkingAddress" : "xxxxxxxxxxxxxxxxxxxxxx",
        "videoRef" : "vvVideoOfEntranceToParkingSpace.mp4" },
    "61JSQnynNWRlN8CxAloEeYOSAxq2" : 
      {"entranceRef" : "ivParkingSpaceEntrance.jpg",
       "latlng" : "lat/lng: (25.028682934478617,121.51116415858267)",
       "myMarkerPosition" : 
         {"latitude" : 25.028682934478617,
          "longitude" : 121.51116415858267},
       "ownershipRef" : "ivCertificateOfOwnership.jpg",
       "parkingAddress" : "xxxxxxxxxxxxxxxxxxxxxx",
       "videoRef" : "vvVideoOfEntranceToParkingSpace.mp4"},
    "HE7UhdnQKjhvHSD3l7QNtQxoElw1" : 
      {"entranceRef" : "ivParkingSpaceEntrance.jpg",
       "latlng" : "lat/lng: (24.797805577018096,120.9950752928853)",
       "myMarkerPosition" : 
        {"latitude" : 24.797805577018096,
         "longitude" : 120.9950752928853},
       "ownershipRef" : "ivCertificateOfOwnership.jpg",
       "parkingAddress" : "xxxxxxxxxxxxxxxxxxxxxx",
       "videoRef" : "vvVideoOfEntranceToParkingSpace.mp4"},
</code></pre>

<p>As for ParkingSpaceData.class is as followings:</p>

<pre><code>public class ParkingSpaceData {
  String parkingAddress;
  String latlng;
  LatLng myMarkerPosition;
  String entranceRef;
  String ownershipRef;
  String videoRef;
  Uri ivParkingSpaceEntranceUri, ivCertificateOfOwnershipUri , vvVideoOfEntranceToParkingSpaceUri;

  public ParkingSpaceData() {}  
  public String getEntranceRef() {return entranceRef;}
  public void setEntranceRef(String entranceRef) {this.entranceRef = entranceRef;}
  public String getLatlng() {return latlng;}
  public void setLatlng(String latlng) {this.latlng = latlng;}
  public LatLng getMyMarkerPosition() {return myMarkerPosition;}
  public void setMyMarkerPosition(LatLng myMarkerPosition) {this.myMarkerPosition = myMarkerPosition;}
  .
  .
  .//getters and setters
  .
  public Uri getIvCertificateOfOwnershipUri() {return ivCertificateOfOwnershipUri;}
  public void setIvCertificateOfOwnershipUri(Uri ivCertificateOfOwnershipUri){this.ivCertificateOfOwnershipUri = ivCertificateOfOwnershipUri;}
  .
  .
  .
</code></pre>