从Internet加载后,图像未在ImageView中显示

发布于 2025-01-27 20:38:28 字数 5342 浏览 4 评论 0原文

这是我使用毕加索和滑行库的代码,但是图像没有在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熊抱啵儿 2025-02-03 20:38:28

添加Android:usescleartexttraffic =“ true”添加到应用程序标签 androidmanifest.xml

从Android 9.0开始(API级28),ClearText支持为
默认情况下禁用。因此,来自HTTP协议的所有请求将不再接受

Add android:usesCleartextTraffic="true" to your Application Tag in your AndroidManifest.xml

Starting with Android 9.0 (API level 28), cleartext support is
disabled by default. So all requests from http protocol will no longer accepted

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文