Home > database >  GlideException: Failed to load resource
GlideException: Failed to load resource

Time:02-06

I encountered the following problem:

2022-02-05 20:42:45.442 14841-14841/com.example.zelenin W/Glide: Load failed for "https://static.devli.ru/public/images/gifs/201401/f17e44ad-497d-434a-bc9b-613f2f1be379.gif" with size [1058x1048] class com.bumptech.glide.load.engine.GlideException: Failed to load resource Program code:

package com.example.zelenin.fragments

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.bumptech.glide.Glide
import com.example.zelenin.R
import com.example.zelenin.databinding.FragmentDevelopersLifeBinding
import java.io.BufferedInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
import kotlin.concurrent.thread


class DevelopersLifeFragment : Fragment(R.layout.fragment_developers_life) {
    //var latch = CountDownLatch(1)
    lateinit var binding: FragmentDevelopersLifeBinding
    private var link: String? = ""

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentDevelopersLifeBinding.inflate(inflater)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        //latch.await()
        getUrl()
        binding.btnNext.setOnClickListener() {
            getUrl()
            Glide
                .with(this)
                .asGif()
                .load(link)
                .centerCrop()
                .into(binding.imgGIF)
        }
    }

    private fun asyncActions(str: String?):String?{

        return link
    }

    private fun getUrl(){
        val a = thread{

            val url: URL = URL("https://developerslife.ru/random?json=true")
            val urlConnection = url.openConnection() as HttpURLConnection
            try {
                var inputStream = BufferedInputStream(urlConnection.inputStream)
                link = readStream(inputStream)
            } finally {
                urlConnection.disconnect()
            }
            link = crutchDontSee(link)
            Log.d("Hello", link!!)
            //latch.countDown()
        }

    }

    private fun readStream(`is`: InputStream): String? {
        return try {
            val bo = ByteArrayOutputStream()
            var i = `is`.read()
            while (i != -1) {
                bo.write(i)
                i = `is`.read()
            }
            bo.toString()
        } catch (e: IOException) {
             ""
        }
    }
     fun crutchDontSee(param:String?):String?{
       var httpsToHttps = param
        httpsToHttps = httpsToHttps?.substringAfter("\"gifURL\":")
        httpsToHttps = httpsToHttps?.substringBefore(",")
        httpsToHttps = "\"https"   httpsToHttps?.substringAfter("http")
        return httpsToHttps
    }

    override fun onDestroyView() {
        super.onDestroyView()
    }



    companion object {
        const val TAG = "DEVELOPERS_LIFE_FRAGMENT"

    }
}

build.gradle:

buildscript {
    repositories {
        google()
        mavenCentral()
}}

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {

    compileSdk 31
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.example.zelenin"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
    implementation "com.github.bumptech.glide:okhttp3-integration:4.12.0"
}


All Error:

2022-02-06 01:02:58.778 516-1989/? I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4
2022-02-06 01:02:58.778 516-1989/? I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4
2022-02-06 01:02:58.783 214-217/? E/[email protected]: Error opening kernel wakelock stats for: wakeup34: Permission denied
2022-02-06 01:02:58.779 214-214/? W/Binder:214_2: type=1400 audit(0.0:1139): avc: denied { read } for name="wakeup34" dev="sysfs" ino=18754 scontext=u:r:system_suspend:s0 tcontext=u:object_r:sysfs:s0 tclass=dir permissive=0
2022-02-06 01:02:58.786 214-217/? E/[email protected]: Error opening kernel wakelock stats for: wakeup35: Permission denied
2022-02-06 01:02:58.783 214-214/? W/Binder:214_2: type=1400 audit(0.0:1140): avc: denied { read } for name="wakeup35" dev="sysfs" ino=18817 scontext=u:r:system_suspend:s0 tcontext=u:object_r:sysfs:s0 tclass=dir permissive=0
2022-02-06 01:02:58.794 19626-19626/com.example.zelenin W/Glide: Load failed for "https://static.devli.ru/public/images/gifs/201303/a8288b73-cca0-4886-b646-46ee73ead7cc.gif" with size [1058x1048]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
2022-02-06 01:02:58.912 516-1999/? I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4
2022-02-06 01:02:58.968 19626-19705/com.example.zelenin D/Hello: "https://static.devli.ru/public/images/gifs/201307/f835354a-c727-418c-a0d7-3eba3b65f67f.gif"
2022-02-06 01:03:01.878 516-1999/? I/system_server: oneway function results will be dropped but finished with status OK and parcel size 4

CodePudding user response:

I try the gif link and got a error: java.io.IOException: Cleartext HTTP traffic to static.devli.ru not permitted. Then I add android:usesCleartextTraffic="true" to the <application> label of the manifest file, now it's OK.

Other solutions: Android 8: Cleartext HTTP traffic not permitted

  •  Tags:  
  • Related