Java 未从firebase获取图像
我尝试了创建自定义适配器类和默认FirebaseRecyclerAdapter的常规方法,但映像加载效率不高 目标是从firebase加载图像,但消息队列很长,请建议一些解决方案 在这个MainActivity.java文件中,我使用了FirebaseRecyclerAdapterJava 未从firebase获取图像,java,android,firebase,picasso,Java,Android,Firebase,Picasso,我尝试了创建自定义适配器类和默认FirebaseRecyclerAdapter的常规方法,但映像加载效率不高 目标是从firebase加载图像,但消息队列很长,请建议一些解决方案 在这个MainActivity.java文件中,我使用了FirebaseRecyclerAdapter public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private GridLayoutM
public class MainActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private GridLayoutManager gridLayoutManager;
private RecyclerView.LayoutManager layoutManager;
private FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
private DatabaseReference databaseReference = firebaseDatabase.getReference();
private DatabaseReference imagesReference = databaseReference.child("Images");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recycler);
gridLayoutManager = new GridLayoutManager(this,2,GridLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setHasFixedSize(true);
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<ImageUrl,MyViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<ImageUrl, MyViewHolder>(
new FirebaseRecyclerOptions.Builder<ImageUrl>().setQuery(imagesReference.limitToLast(50),ImageUrl.class).build()
) {
@Override
protected void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull ImageUrl model) {
holder.setDetails(getApplicationContext(),model.getUrl());
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_grid_layout,parent,false);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
}
}
我是这样进入logcat的:
2021-04-14 00:47:19.148 4019-4048/com.example.thoughtsdemo E/ion: ioctl c0044901 failed with code -1: Invalid argument
2021-04-14 00:47:19.475 4019-4045/com.example.thoughtsdemo W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
2021-04-14 00:47:19.477 4019-4045/com.example.thoughtsdemo I/System.out: e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
2021-04-14 00:47:19.950 4019-4045/com.example.thoughtsdemo D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
2021-04-14 00:47:19.951 4019-4045/com.example.thoughtsdemo D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
2021-04-14 13:31:51.560 30382-30382/com.example.thoughtsdemo E/ANR_LOG: >>> msg's executing time is too long
2021-04-14 13:31:51.560 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Blocked msg = { when=-1m33s688ms what=159 target=android.app.ActivityThread$H obj=android.app.servertransaction.ClientTransaction@fb63a696 } , cost = 90743 ms
2021-04-14 13:31:51.560 30382-30382/com.example.thoughtsdemo E/ANR_LOG: >>>Current msg List is:
2021-04-14 13:31:51.561 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <1> = { when=-1m33s432ms what=149 target=android.app.ActivityThread$H obj=android.os.BinderProxy@622d88c }
2021-04-14 13:31:51.562 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <2> = { when=-1m30s168ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2021-04-14 13:31:51.562 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <3> = { when=-1m30s162ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <4> = { when=-1m20s754ms what=132 target=android.app.ActivityThread$H }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <5> = { when=-26ms what=0 target=android.view.ViewRootImpl$ViewRootHandler callback=android.view.ViewRootImpl$4 }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <6> = { when=-9ms barrier=0 }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<
红色的logcat显示如下:
2021-04-14 00:47:19.148 4019-4048/com.example.thoughtsdemo E/ion: ioctl c0044901 failed with code -1: Invalid argument
2021-04-14 00:47:19.475 4019-4045/com.example.thoughtsdemo W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
2021-04-14 00:47:19.477 4019-4045/com.example.thoughtsdemo I/System.out: e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaHttp
2021-04-14 00:47:19.950 4019-4045/com.example.thoughtsdemo D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
2021-04-14 00:47:19.951 4019-4045/com.example.thoughtsdemo D/OpenSSLLib: OpensslErr:Module:12(177:); file:external/boringssl/src/crypto/asn1/asn1_lib.c ;Line:168;Function:ASN1_get_object
2021-04-14 13:31:51.560 30382-30382/com.example.thoughtsdemo E/ANR_LOG: >>> msg's executing time is too long
2021-04-14 13:31:51.560 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Blocked msg = { when=-1m33s688ms what=159 target=android.app.ActivityThread$H obj=android.app.servertransaction.ClientTransaction@fb63a696 } , cost = 90743 ms
2021-04-14 13:31:51.560 30382-30382/com.example.thoughtsdemo E/ANR_LOG: >>>Current msg List is:
2021-04-14 13:31:51.561 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <1> = { when=-1m33s432ms what=149 target=android.app.ActivityThread$H obj=android.os.BinderProxy@622d88c }
2021-04-14 13:31:51.562 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <2> = { when=-1m30s168ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2021-04-14 13:31:51.562 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <3> = { when=-1m30s162ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <4> = { when=-1m20s754ms what=132 target=android.app.ActivityThread$H }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <5> = { when=-26ms what=0 target=android.view.ViewRootImpl$ViewRootHandler callback=android.view.ViewRootImpl$4 }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: Current msg <6> = { when=-9ms barrier=0 }
2021-04-14 13:31:51.563 30382-30382/com.example.thoughtsdemo E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<
}
当我使用Log.d()在onBindViewHolder中显示获取的url时,我并没有打印url,所以问题在于:
protected void onBindViewHolder(@NonNull MyViewHolder holder, int position, @NonNull ImageUrl model) {
Log.d("url",model.getUrl());
holder.setDetails(getApplicationContext(),model.getUrl());
}
当我使用Glide时,在logcat中用红色书写
2021-04-14 17:28:03.148 16789-16789/com.example.thoughtsdemo E/ANR_LOG: >>> msg's executing time is too long
2021-04-14 17:28:03.148 16789-16789/com.example.thoughtsdemo E/ANR_LOG: Blocked msg = { when=-34s879ms what=159 target=android.app.ActivityThread$H obj=android.app.servertransaction.ClientTransaction@7f3731c5 } , cost = 31829 ms
2021-04-14 17:28:03.148 16789-16789/com.example.thoughtsdemo E/ANR_LOG: >>>Current msg List is:
2021-04-14 17:28:03.149 16789-16789/com.example.thoughtsdemo E/ANR_LOG: Current msg <1> = { when=-34s610ms what=149 target=android.app.ActivityThread$H obj=android.os.BinderProxy@622d88c }
2021-04-14 17:28:03.149 16789-16789/com.example.thoughtsdemo E/ANR_LOG: Current msg <2> = { when=-31s140ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2021-04-14 17:28:03.150 16789-16789/com.example.thoughtsdemo E/ANR_LOG: Current msg <3> = { when=-31s134ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2 }
2021-04-14 17:28:03.150 16789-16789/com.example.thoughtsdemo E/ANR_LOG: Current msg <4> = { when=-21s840ms what=132 target=android.app.ActivityThread$H }
2021-04-14 17:28:03.151 16789-16789/com.example.thoughtsdemo E/ANR_LOG: Current msg <5> = { when=-37ms what=0 target=android.view.ViewRootImpl$ViewRootHandler callback=android.view.ViewRootImpl$4 }
2021-04-14 17:28:03.151 16789-16789/com.example.thoughtsdemo E/ANR_LOG: Current msg <6> = { when=-10ms barrier=0 }
2021-04-14 17:28:03.151 16789-16789/com.example.thoughtsdemo E/ANR_LOG: >>>CURRENT MSG DUMP OVER<<<
2021-04-14 17:28:03.148 16789-16789/com.example.thoughtsdemo E/ANR\u LOG:>>>消息的执行时间太长
2021-04-14 17:28:03.148 16789-16789/com.example.thoughtsdemo E/ANR_LOG:Blocked msg={when=-34s879ms what=159 target=android.app.ActivityThread$H obj=android.app.servertransaction。ClientTransaction@7f3731c5},成本=31829毫秒
2021-04-14 17:28:03.148 16789-16789/com.example.thoughtsdemo E/ANR_LOG:>>>当前消息列表为:
2021-04-14 17:28:03.149 16789-16789/com.example.thoughtsdemo E/ANR_LOG:Current msg={when=-34s610ms what=149 target=android.app.ActivityThread$H obj=android.os。BinderProxy@622d88c }
2021-04-14 17:28:03.149 16789-16789/com.example.thoughtsdemo E/ANR_LOG:Current msg={when=-31s140ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2}
2021-04-14 17:28:03.150 16789-16789/com.example.thoughtsdemo E/ANR_LOG:Current msg={when=-31s134ms what=0 target=android.os.Handler callback=androidx.core.content.res.ResourcesCompat$FontCallback$2}
2021-04-14 17:28:03.150 16789-16789/com.example.thoughtsdemo E/ANR_LOG:Current msg={when=-21s840ms what=132 target=android.app.ActivityThread$H}
2021-04-14 17:28:03.151 16789-16789/com.example.thoughtsdemo E/ANR_LOG:Current msg={when=-37ms what=0 target=android.view.ViewRootImpl$ViewRootHandler callback=android.view.ViewRootImpl$4}
2021-04-14 17:28:03.151 16789-16789/com.example.thoughtsdemo E/ANR_LOG:Current msg={when=-10ms barrier=0}
2021-04-14 17:28:03.151 16789-16789/com.example.thoughtsdemo E/ANR_LOG:>>>当前消息转储超过使用Glide
添加依赖项:
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
Glide.with(CONTEXT).load(URL).into(IMAGE_VIEW);
如何加载图像:
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
Glide.with(CONTEXT).load(URL).into(IMAGE_VIEW);
注意:替换为您自己的值
请随意询问是否有不清楚的地方。您是否使用了调试器来识别在哪一行出现了此错误?可能是您的Uri.parse(url)
@youshabinar有问题,如果我尝试过调试,但没有显示出问题,在logcat中,它以红色显示如下:@coroutineDispatcher我尝试了不同的方法,但“URL”没有问题。我尝试了实现Glide,但仍然没有获取图像,我编辑了关于我面临的问题的问题。请在使用Glide后更新日志。我已经更新了日志。请帮忙。我发现这不是毕加索或格莱德的问题。请看我在问题中的第一个日志。请提出解决方案