0
interpreter.run(inputs, inputOutputOptions)
                .addOnSuccessListener(
                        new OnSuccessListener<FirebaseModelOutputs>() {
                            @Override
                            public void onSuccess(FirebaseModelOutputs result) {
                                String str;
                                float[][] output = result.getOutput(0);
                               float[] probabilities = output[0];
                                float res=probabilities[0];
                                //Log.d(TAG, "onSuccess res: "+result.getOutput(0).toString());
                                System.out.println(output[0][0]);
                                System.out.println(output[0][1]);
                                if (output[0][0]>output[0][1]){
                                  //till here my code is properly Running
                                    str="Class1";
                                  graphicOverlay.add(new FaceGraphic(graphicOverlay, face,str));
                                //But when i try to call this method this method not getting called same for else case

                                }
                                else {
                               //till here my code is properly Running
                                    str="Class2";
                                }
                            }
                        })
                .addOnFailureListener(
                        new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {

                            }
                        });

How can i get the value of of variable "str" in my main method?
I tried declaring string as a Static Class but it gives the last stored output(value of str is not updated as it changes)
Thankyou in advanced

codeBlue
  • 1
  • 1
  • 2
  • It's not that you can't access the variable outside of `onSuccess`, it's just that `onSuccess` hasn't been called yet. If you place some logging in both places you can see that. Any code that needs data from `FirebaseModelOutputs` needs to be inside `onSuccess` or be called from there. Also see https://stackoverflow.com/questions/50434836/getcontactsfromfirebase-method-return-an-empty-list/50435519#50435519 – Frank van Puffelen Jun 30 '20 at 04:10
  • If you are using Firebase Realtime Database, please check **[this](https://stackoverflow.com/questions/47847694/how-to-return-datasnapshot-value-as-a-result-of-a-method/47853774)** out. If you are using Cloud Firestore, please check **[this](https://stackoverflow.com/questions/48499310/how-to-return-a-documentsnapshot-as-a-result-of-a-method/48500679#48500679)** out. – Alex Mamo Jun 30 '20 at 09:43

0 Answers0