Android 滑动罐';t下载图像到ImageView
我正在从iOS切换到Android,并尝试通过URL下载图像,对于这个问题,我发现许多开发人员更喜欢使用Glide库,我正在尝试下载图像,但不理解为什么我会看到错误图像。请查看我的代码,说出我做错了什么 此错误发生在JPEG和PNG格式中。 Glide版本4.12.0 代码: 日志: 滑动日志:Android 滑动罐';t下载图像到ImageView,android,image,download,android-glide,Android,Image,Download,Android Glide,我正在从iOS切换到Android,并尝试通过URL下载图像,对于这个问题,我发现许多开发人员更喜欢使用Glide库,我正在尝试下载图像,但不理解为什么我会看到错误图像。请查看我的代码,说出我做错了什么 此错误发生在JPEG和PNG格式中。 Glide版本4.12.0 代码: 日志: 滑动日志: 2021-04-01 11:49:06.119 18374-18374/com.example.testglideandpicasso W/Glide: Failed to find Generated
2021-04-01 11:49:06.119 18374-18374/com.example.testglideandpicasso W/Glide: Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored
2021-04-01 11:49:06.468 18374-18374/com.example.testglideandpicasso W/Glide: Load failed for http://developer.alexanderklimov.ru/android/images/android_cat.jpg with size [1173x746]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 root cause:
com.bumptech.glide.load.HttpException(Failed to connect or obtain data, status code: -1)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.HttpException: Failed to connect or obtain data, status code: -1
2021-04-01 11:49:06.471 18374-18374/com.example.testglideandpicasso I/Glide: Root cause (1 of 1)
com.bumptech.glide.load.HttpException: Failed to connect or obtain data, status code: -1
at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:98)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:58)
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:311)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:280)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)
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)
Caused by: java.io.IOException: Cleartext HTTP traffic to developer.alexanderklimov.ru 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:93)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:58)
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:311)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:280)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)
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)
我认为您的AndroidManifest.xml中缺少互联网权限。 请在AndroidManifest.xml文件中的应用程序元素之前定义权限
<uses-permission android:name="android.permission.INTERNET" />
Android平台上的任何internet请求都必须具有此权限,有关更多权限,请查看Android开发者文档:
祝你的Android开发旅途愉快 我认为您的AndroidManifest.xml中缺少INTERNET权限。 请在AndroidManifest.xml文件中的应用程序元素之前定义权限
<uses-permission android:name="android.permission.INTERNET" />
Android平台上的任何internet请求都必须具有此权限,有关更多权限,请查看Android开发者文档:
祝你的Android开发旅途愉快 我检查了日志,并尝试使用此帖子解决我的问题 上面的例子在某些情况下会很好,但对于我的问题解决方案,需要在清单文件中添加允许清除HTTP流量
android:usesCleartextTraffic="true"
我的所有清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testglideandpicasso">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TestGlideAndPicasso">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我检查了日志,并尝试使用此帖子解决我的问题 上面的例子在某些情况下会很好,但对于我的问题解决方案,需要在清单文件中添加允许清除HTTP流量
android:usesCleartextTraffic="true"
我的所有清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testglideandpicasso">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TestGlideAndPicasso">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在清单中添加网络安全配置xml文件 res/xml/network\u security\u config.xml:
- 在资源xml文件夹中创建networksecurity config.xml
developer.alexanderklimov.ru/
- 在清单中添加networksecurity config.xml,如下所示
在清单中添加网络安全配置xml文件 res/xml/network\u security\u config.xml:
- 在资源xml文件夹中创建networksecurity config.xml
developer.alexanderklimov.ru/
- 在清单中添加networksecurity config.xml,如下所示
你能分享你的glide日志吗?你能分享你的glide日志吗?对不起,但是另一个地方的问题:(对不起,但是另一个地方的问题:(
<application
android:name=".MyApplication"
android:networkSecurityConfig="@xml/network_security_config" ... />