itz Prateek
itz Prateek

Reputation: 101

Fetching Image Issue from firebase using Picasso

I have done with the text feteching from the database, buit while fetching image from the database using picasso the images are not loading the phone and the logcat is displaying the error :

com.example.lenovo.skanda E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.

The textviews are easily getting fetching from the firebase. But in case of ImageView its not loading properly.

QuoteList.java

public class QuoteList extends AppCompatActivity {

    private StorageReference storageRef;

    RecyclerView  mRecyclerView;
    FirebaseDatabase mFirebaseDatabase;
    DatabaseReference mReference;

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

        //ActionBar actionBar = getSupportActionBar();
        //getSupportActionBar().setTitle("Quotes");
        //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        //getSupportActionBar().setHomeButtonEnabled(true);

        final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView = findViewById(R.id.quotes_list);
        mRecyclerView.setLayoutManager(layoutManager);


        mFirebaseDatabase = FirebaseDatabase.getInstance();
        mReference = mFirebaseDatabase.getReference("Quotes");
    }





    @Override
    protected void onStart() {
        super.onStart();

        FirebaseRecyclerAdapter<Quote, QuoteViewHolder> firebaseRecyclerAdapter =
                new FirebaseRecyclerAdapter<Quote, QuoteViewHolder>(
                        Quote.class,
                        R.layout.quote_row,
                        QuoteViewHolder.class,
                        mReference
                ) {

                    @Override
                    protected void populateViewHolder(QuoteViewHolder viewHolder , Quote model , int position) {

                     //   viewHolder.setDetails(getApplicationContext(), model.getQuotes(), model.getQuote_Author(), model.getImages());
                            viewHolder.setQuotes(model.getQuotes());
                            viewHolder.setQuoteAuthor(model.getQuote_Author());
                            viewHolder.setImage(getApplicationContext(),model.getImages());


                    }
                };

        mRecyclerView.setAdapter(firebaseRecyclerAdapter);

    }

    public static class QuoteViewHolder extends RecyclerView.ViewHolder{

        View mView;

        public QuoteViewHolder(View itemView) {
            super(itemView);

            mView = itemView;
        }

        public void setQuotes(String Quote){
            TextView post_quote = (TextView) mView.findViewById(R.id.post_quote);
            post_quote.setText(Quote);
        }

        public void setQuoteAuthor(String QuoteAuthor){
            TextView post_quoteAuthor = (TextView) mView.findViewById(R.id.post_author);
            post_quoteAuthor.setText(QuoteAuthor);
        }

        public void setImage(Context ctx, String image){
            ImageView post_image = (ImageView) mView.findViewById(R.id.post_image);
            Picasso.get().load(image).into(post_image);

        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.main_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }
}

I am also attaching the logcat error report. Please go through it.

    11-04 16:16:37.413 6688-7596/com.example.lenovo.skanda E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
11-04 16:16:39.547 6688-7596/com.example.lenovo.skanda E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
11-04 16:16:40.567 6688-7596/com.example.lenovo.skanda E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
11-04 16:16:41.948 6688-7596/com.example.lenovo.skanda E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
11-04 16:16:44.661 6688-7596/com.example.lenovo.skanda E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
11-04 16:16:48.528 6688-7603/com.example.lenovo.skanda E/StorageUtil: error getting token java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.
11-04 16:24:46.716 6688-6698/com.example.lenovo.skanda E/System: Uncaught exception thrown by finalizer
11-04 16:24:46.717 6688-6698/com.example.lenovo.skanda E/System: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.android.org.conscrypt.SslWrapper.isClosed()' on a null object reference
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.free(ConscryptFileDescriptorSocket.java:986)
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.finalize(ConscryptFileDescriptorSocket.java:1014)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:252)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:239)
        at java.lang.Daemons$Daemon.run(Daemons.java:105)
        at java.lang.Thread.run(Thread.java:764)
    Uncaught exception thrown by finalizer
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.android.org.conscrypt.SslWrapper.isClosed()' on a null object reference
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.free(ConscryptFileDescriptorSocket.java:986)
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.finalize(ConscryptFileDescriptorSocket.java:1014)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:252)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:239)
        at java.lang.Daemons$Daemon.run(Daemons.java:105)
        at java.lang.Thread.run(Thread.java:764)
    Uncaught exception thrown by finalizer
11-04 16:24:46.718 6688-6698/com.example.lenovo.skanda E/System: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.android.org.conscrypt.SslWrapper.isClosed()' on a null object reference
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.free(ConscryptFileDescriptorSocket.java:986)
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.finalize(ConscryptFileDescriptorSocket.java:1014)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:252)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:239)
        at java.lang.Daemons$Daemon.run(Daemons.java:105)
        at java.lang.Thread.run(Thread.java:764)
    Uncaught exception thrown by finalizer
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.android.org.conscrypt.SslWrapper.isClosed()' on a null object reference
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.free(ConscryptFileDescriptorSocket.java:986)
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket.finalize(ConscryptFileDescriptorSocket.java:1014)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:252)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:239)
        at java.lang.Daemons$Daemon.run(Daemons.java:105)
        at java.lang.Thread.run(Thread.java:764)

Please help me out. Thank you in advance.

Upvotes: 0

Views: 1188

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138824

You are getting the follwing error:

java.util.concurrent.ExecutionException: com.google.firebase.internal.api.FirebaseNoSignedInUserException: Please sign in before trying to get a token.

Because by default, your are security rules require your user to be authenticated.

allow read, write: if request.auth != null;

To solve this, you can either make sure your user is authenticated before trying to diplay the image or change the security rules to:

allow read, write;

But I recommend you to use these rules only for testing purposes. Don't keep this rules always like this. Secure your Firebase realtime database, as well as Firebase Storage.

Upvotes: 2

Related Questions