使用Android Kotlin加载图像
为什么我不能加载带有URL的图像,已经使用了线圈依赖项使用Android Kotlin加载图像,android,kotlin,Android,Kotlin,为什么我不能加载带有URL的图像,已经使用了线圈依赖项 implementation "io.coil-kt:coil:0.11.0" 然后在清单中添加internet权限,如下所示 <uses-permission android:name="android.permission.INTERNET" /> 但是,如果我从本地或drawable加载它,它的加载没有问题 holder.musicImage.load(R.drawable.ic
implementation "io.coil-kt:coil:0.11.0"
然后在清单中添加internet权限,如下所示
<uses-permission android:name="android.permission.INTERNET" />
但是,如果我从本地或drawable加载它,它的加载没有问题
holder.musicImage.load(R.drawable.ic_baseline_account_box_24)
有什么问题?有人能帮忙吗?我正在使用一个线圈作为库。你有什么错误吗
我建议使用毕加索,因为它比这更有力
不管怎样,我使用这个代码
val imageView:ImageView = findViewById(R.id.image_view)
imageView!!.load("https://upload.wikimedia.org/wikipedia/commons/thumb/7/74/Kotlin-logo.svg/1024px-Kotlin-logo.svg.png")
但是有些东西是你应该注意的
一,-
在app/build.gradle中
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
二,-
必须为线圈工作添加com.squareup.okhttp3:okhttp:3.12.11库
因为线圈使用okhttp进行工作
这样做吧
dependencies {
...
implementation 'com.squareup.okhttp3:okhttp:3.12.11'
}
我做了,它工作得很好我修复了只需擦除模拟器中的数据并重新运行,可能我的项目已损坏或与其他项目同名,无论如何thx寻求帮助
dependencies {
...
implementation 'com.squareup.okhttp3:okhttp:3.12.11'
}