当我将此方法放在onCreate上时,我给了我这个错误 java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'int java.lang.Long.intValue()'
im试图将当前数据库中的“硬币”总数放入Textview中
public void showtotalcoins(){
mShowTotalCoins= findViewById(R.id.numerCoinstxt);
FirebaseFirestore db1= FirebaseFirestore.getInstance();
DocumentReference showTickets= db1.document("Tickets/TotalTickets");
showTickets.get().addOnSuccessListener(new
OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
coins = documentSnapshot.getLong("Tickets").intValue();
showTotalCoins= coins*50;
mShowTotalCoins.setText(""+showTotalCoins);
}
});
}
xml
<TextView
android:id="@+id/numerCoinstxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="-"
android:textSize="70sp"
app:layout_constraintBottom_toTopOf="@+id/mticket"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.489"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/TotalCoinx"
app:layout_constraintVertical_bias="0.496"