java - 使用 Picasso 从 Firebase 获取图像问题
问题描述
我已经完成了从数据库中获取文本的操作,但是在使用 picasso 从数据库中获取图像时,图像没有加载手机并且 logcat 显示错误:
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.
文本视图很容易从火力库中获取。但在 ImageView 的情况下,它不能正确加载。
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);
}
}
我还附上了 logcat 错误报告。请通过它。
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)
请帮帮我。先感谢您。
解决方案
您收到以下错误:
java.util.concurrent.ExecutionException:com.google.firebase.internal.api.FirebaseNoSignedInUserException:请先登录,然后再尝试获取令牌。
因为默认情况下,您的安全规则要求您的用户进行身份验证。
allow read, write: if request.auth != null;
要解决此问题,您可以在尝试显示图像之前确保您的用户已通过身份验证,或者将安全规则更改为:
allow read, write;
但我建议您仅将这些规则用于测试目的。不要总是这样保持这个规则。保护您的 Firebase 实时数据库以及 Firebase 存储。
推荐阅读
- android - 使用Transition引起的问题
- android-studio - 在 Android Studio 中,“Layout Captures”工具有什么用
- python - 如何将关键字附加到 JPG 图像中的 IPTC 数据?
- html - 我想在 ng-repeat 循环中绑定动态计数值?
- laravel - 如何在 Laravel 的对象变量中获取随机行?
- javascript - 使用 Angular 创建可缩放的树形网页
- angular - 如何在自定义验证器中使用可注入服务
- javascript - 根据另一个自定义数组对数组中的对象属性进行排序
- google-apps-script - 基于 Google Sheet 电子表格的触发器停止工作
- java - 如何检查firebase中是否存在值