从Internet加载后,图像未在ImageView中显示
这是我使用毕加索和滑行库的代码,但是图像没有在imageView
中显示。我什至尝试过HTTP方法,我还没有工作,
String icon = pojo.getCurrent().getWeather().get(0).getIcon();
String iconUrl = "http://openweathermap.org/img/w/" + icon + ".png";
Log.v("AAA",iconUrl);
//Picasso.get().load(iconUrl).resize(20,20).centerCrop().into(weatherImage);
Glide.with(requireActivity().getApplicationContext()).load(iconUrl).into(weatherImage);
我还添加了依赖项
,这是
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:orientation="horizontal">
<Button
android:id="@+id/id_weather_refresh"
android:layout_width="30dp"
android:layout_height="40dp"
android:drawableEnd="@drawable/ic_baseline_refresh"
android:padding="5dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/id_temperature"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:fontFamily="casual"
android:gravity="center"
android:text="-:-/-:-"
android:textColor="#040404"
android:textSize="34sp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_envType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|center_vertical"
android:text="---------"
android:textColor="#716F6F" />
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="110dp"
android:layout_height="110dp"
app:cardCornerRadius="20dp">
<ImageView
android:id="@+id/id_weatherImage"
android:layout_width="110dp"
android:layout_height="110dp"
android:src="@drawable/ic_launcher_background" />
</androidx.cardview.widget.CardView>
</LinearLayout>
我发布了正在发生的事情的布局文件,实际上它必须从Internet下载图像并在此处显示,但是它没有显示任何内容。
这是 url 图像
错误消息
2022-05-11 17:06:31.754 12117-12117/com.example.clothme I/Glide: Root cause (1 of 1)
java.io.IOException: Cleartext HTTP traffic to openweathermap.org not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:127)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:100)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:56)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:62)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
2022-05-11 17:06:32.362 12117-16853/com.example.clothme I/example.clothm: Waiting for a blocking GC Instrumentation
2022-05-11 17:06:35.370 12117-16853/com.example.clothme I/example.clothm: Waiting for a blocking GC Instrumentation
2022-05-11 17:06:35.379 12117-16853/com.example.clothme I/example.clothm: WaitForGcToComplete blocked Instrumentation on ProfileSaver for 9.615ms
Here is my code where I used Picasso as well as glide library, but the image did not get displayed in the ImageView
. I even tried HTTP method, didn't work
String icon = pojo.getCurrent().getWeather().get(0).getIcon();
String iconUrl = "http://openweathermap.org/img/w/" + icon + ".png";
Log.v("AAA",iconUrl);
//Picasso.get().load(iconUrl).resize(20,20).centerCrop().into(weatherImage);
Glide.with(requireActivity().getApplicationContext()).load(iconUrl).into(weatherImage);
I also added the dependencies
this is the layout file
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:orientation="horizontal">
<Button
android:id="@+id/id_weather_refresh"
android:layout_width="30dp"
android:layout_height="40dp"
android:drawableEnd="@drawable/ic_baseline_refresh"
android:padding="5dp"
android:textColor="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/id_temperature"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:fontFamily="casual"
android:gravity="center"
android:text="-:-/-:-"
android:textColor="#040404"
android:textSize="34sp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_envType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|center_vertical"
android:text="---------"
android:textColor="#716F6F" />
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="110dp"
android:layout_height="110dp"
app:cardCornerRadius="20dp">
<ImageView
android:id="@+id/id_weatherImage"
android:layout_width="110dp"
android:layout_height="110dp"
android:src="@drawable/ic_launcher_background" />
</androidx.cardview.widget.CardView>
</LinearLayout>
I have posted an image of what's happening, actually it has to download the image from internet and display it there, but instead it's not displaying anything.
This is the URL of the image
The error message
2022-05-11 17:06:31.754 12117-12117/com.example.clothme I/Glide: Root cause (1 of 1)
java.io.IOException: Cleartext HTTP traffic to openweathermap.org not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:127)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:462)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:100)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:56)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:164)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:62)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
2022-05-11 17:06:32.362 12117-16853/com.example.clothme I/example.clothm: Waiting for a blocking GC Instrumentation
2022-05-11 17:06:35.370 12117-16853/com.example.clothme I/example.clothm: Waiting for a blocking GC Instrumentation
2022-05-11 17:06:35.379 12117-16853/com.example.clothme I/example.clothm: WaitForGcToComplete blocked Instrumentation on ProfileSaver for 9.615ms
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加
Android:usescleartexttraffic =“ true”
添加到应用程序标签androidmanifest.xml
Add
android:usesCleartextTraffic="true"
to your Application Tag in yourAndroidManifest.xml