简体   繁体   中英

Getting an error while retrieving a number from a Firestore document

I stored a number in a field of a document and want to retrieve it but I get the following error: String resource ID #0x1

I am using this method to retrieve the number. Is the number stored in Firestore as Long, Integer or Double? I didn't find any answer to that, and how can I resolve this error so I can retrieve the number and use it in my code?

The error is displayed in the Toast line.

Your help is very much appreciated!

Here is my code:

    Integer round;

    private FirebaseFirestore db = FirebaseFirestore.getInstance();
    private CollectionReference roundRef = db.collection("Games");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_interim_result);

       ...

        roundRef.document(gameId).collection("Round").document("Round").get()
                .addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                        if (task.isSuccessful()){
                            DocumentSnapshot document = task.getResult();
                            if (document != null){

                                round = document.getLong("round").intValue();

                                Toast.makeText(PlayInterimResultMainActivity.this, round, Toast.LENGTH_SHORT).show();

                            }
                        }
                    }
                });
...

I found the problem:

The error was in the Toast message, where I didn't transformed the integer into a String value. Here is the right Toast message:

Toast.makeText(PlayInterimResultMainActivity.this, round.toString(), Toast.LENGTH_SHORT).show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM