NullPOinterexception while fetching sharedpreference data

final String[] message = new String[1];

Query lastQuery = mFetchingMessages.orderByKey().limitToLast(1);

lastQuery.addValueEventListener(new ValueEventListener() {

@Override

public void onDataChange(DataSnapshot dataSnapshot) {

message[0] = dataSnapshot.getKey();

editor1 = PreferenceManager.getDefaultSharedPreferences(getApplication()).edit();

editor1.putString("LastMessage", message[0]);

editor1.apply();

}

@Override

public void onCancelled(DatabaseError databaseError) {

}

});

Query fetch = mFetchingMessages.child("Message").startAt(mSharedPreferences1.getString("LastMessage", message[0]));

fetch.addValueEventListener(new ValueEventListener() {

@Override

public void onDataChange(DataSnapshot dataSnapshot) {

mMessages();

mMessagesRecieved();

}

@Override

public void onCancelled(DatabaseError databaseError) {

}

});

Trying to make a basic chat app.. So im trying to get the last message key in the database and use that as start key for executing a method... That is get the number of new childs added... So for getting the number of new childs added im trying this code but getting...

Read More »

By: StackOverFlow - Tuesday, 20 November

Related Posts