I have values in Firebase database and I just want to have it as a int variable.
I want to have coinsAmount in a variable in the project.
I was looking for a lot of information but could not understand because most of the information in English and I do not fully understand the translation of Google translator please tell me how to do it or throw off where it is written please
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
int coinsAmount = dataSnapshot.child("coinsAmount").getValue(Long.class);
text.setText(coinsAmount);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
}
};
uidRef.addListenerForSingleValueEvent(valueEventListener);
int coinsAmount = dataSnapshot.child("coinsAmount").getValue(Long.class);
says:
Incompatible types. Required int but 'getValue' was inferred to T: Incompatible types: Long is not convertible to int
uidRef.addListenerForSingleValueEvent(valueEventListener);
says:
Cannot resolve symbol 'addListenerForSingleValueEvent
https://i.stack.imgur.com/PpU7n.png
initializing in activity
public class MenuActivity extends BaseActivity {
public TextView text;
private static final String TAG = "MenuActivity";
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference uidRef = rootRef.child("users").child(getUid());