我试图做所有事情,但没有成功。 我检查了该链接一千次,并在浏览器中将其打开,效果很好。 但是另一个链接可以正常工作
有人告诉我为什么此代码不起作用吗?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
Picasso.get()
.load("https://1.bp.blogspot.com/-qgZfrkC0FWw/XPWFD8BtcOI/AAAAAAABcs4/S8KFUqFgVtgrmMn5CZ7J8UkKLM1OQ6FVACLcBGAs/s640/Firefox%2BLockwise.jpg")
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageView)
}
}
我的布局代码是:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:id="@+id/coordinatorLayout">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
tools:layout_conversion_absoluteHeight="56dp"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_conversion_absoluteWidth="411dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:popupTheme="@style/AppTheme.PopupOverlay"
tools:layout_conversion_absoluteHeight="56dp"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_conversion_absoluteWidth="411dp">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:layout_conversion_absoluteHeight="675dp"
tools:layout_editor_absoluteY="56dp"
tools:layout_editor_absoluteX="0dp"
tools:layout_conversion_absoluteWidth="411dp">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
然后登录:
06/04 10:11:44: Launching app
$ adb install-multiple -r -t D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\dep\dependencies.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_1.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_0.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_2.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_3.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_5.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_4.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_6.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_7.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_8.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\split-apk\debug\slices\slice_9.apk D:\AndroidStudioProjects\MyBlog\app\build\intermediates\instant-run-apk\debug\app-debug.apk
Split APKs installed in 32 s 391 ms
$ adb shell am start -n "com.alisaki.myblog/com.alisaki.myblog.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 31943 on device samsung-sm_j320f-420009d1f0c85400
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
E/Zygote: MountEmulatedStorage()
v2
I/SELinux: Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-J320F_5.1.1_0072
E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
I/art: Late-enabling -Xcheck:jni
E/art: setrlimit(RLIMIT_CORE) failed for pid 31943: Operation not permitted
I/libpersona: KNOX_SDCARD checking this for 10113
KNOX_SDCARD not a persona
I/InjectionManager: Inside getClassLibPath + mLibMap{0=, 1=}
W/ResourcesManager: getTopLevelResources: /data/app/com.alisaki.myblog-2/base.apk / 1.0 running in com.alisaki.myblog rsrc of package com.alisaki.myblog
D/ResourcesManager: For user 0 new overlays fetched Null
I/InjectionManager: Inside getClassLibPath caller
I/InstantRun: starting instant run server: is main process
D/InjectionManager: InjectionManager
fillFeatureStoreMap com.alisaki.myblog
I/InjectionManager: Constructor com.alisaki.myblog, Feature store :{}
featureStore :{}
W/ResourcesManager: getTopLevelResources: /data/app/com.alisaki.myblog-2/base.apk / 1.0 running in com.alisaki.myblog rsrc of package com.alisaki.myblog
W/ResourcesManager: getTopLevelResources: /data/app/com.alisaki.myblog-2/base.apk / 1.0 running in com.alisaki.myblog rsrc of package com.alisaki.myblog
W/ResourceType: Failure getting entry for 0x01080947 (t=7 e=2375) (error -75)
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
D/PhoneWindow: *FMB* installDecor mIsFloating : false
*FMB* installDecor flags : -2139029248
I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
D/TextView: setTypeface with style : 0
setTypeface with style : 0
D/Activity: performCreate Call Injection manager
I/InjectionManager: dispatchOnViewCreated > Target : com.alisaki.myblog.MainActivity isFragment :false
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: false
D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
*FMB* isFloatingMenuEnabled return false
W/System.err: remove failed: ENOENT (No such file or directory) : /data/data/com.alisaki.myblog/cache/picasso-cache/journal.tmp
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Get maximum texture size. GL_MAX_TEXTURE_SIZE is 4096
Enabling debug mode 0
W/art: Before Android 4.1, method int androidx.appcompat.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
I/InjectionManager: dispatchCreateOptionsMenu :com.alisaki.myblog.MainActivity
dispatchPrepareOptionsMenu :com.alisaki.myblog.MainActivity
I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@25ceb117 time:28955475
AndroidManifest.xml内容:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alisaki.myblog">
<uses-permission android:name="android.permission.INTERNET"/>
<application
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/AppTheme">
<activity android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Logcat:
06-04 10:24:54.753 32201-32201/? E/Zygote: MountEmulatedStorage()
06-04 10:24:54.753 32201-32201/? E/Zygote: v2
06-04 10:24:54.753 32201-32201/? I/libpersona: KNOX_SDCARD checking this for 10113
06-04 10:24:54.753 32201-32201/? I/libpersona: KNOX_SDCARD not a persona
06-04 10:24:54.753 32201-32201/? I/SELinux: Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-J320F_5.1.1_0072
06-04 10:24:54.753 32201-32201/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
06-04 10:24:54.753 32201-32201/? I/art: Late-enabling -Xcheck:jni
06-04 10:24:54.753 32201-32201/? E/art: setrlimit(RLIMIT_CORE) failed for pid 32201: Operation not permitted
06-04 10:24:54.803 32201-32208/? I/art: Debugger is no longer active
06-04 10:24:54.823 32201-32201/? W/ResourcesManager: getTopLevelResources: /data/app/com.alisaki.myblog-2/base.apk / 1.0 running in com.alisaki.myblog rsrc of package com.alisaki.myblog
06-04 10:24:54.833 32201-32201/? I/InjectionManager: Inside getClassLibPath + mLibMap{0=, 1=}
06-04 10:24:54.843 32201-32201/? D/ResourcesManager: For user 0 new overlays fetched Null
06-04 10:24:54.843 32201-32201/? I/InjectionManager: Inside getClassLibPath caller
06-04 10:24:55.474 32201-32201/? I/InstantRun: starting instant run server: is main process
06-04 10:24:55.474 32201-32201/? D/InjectionManager: InjectionManager
06-04 10:24:55.474 32201-32201/? D/InjectionManager: fillFeatureStoreMap com.alisaki.myblog
06-04 10:24:55.474 32201-32201/? I/InjectionManager: Constructor com.alisaki.myblog, Feature store :{}
06-04 10:24:55.474 32201-32201/? I/InjectionManager: featureStore :{}
06-04 10:24:55.594 32201-32201/? W/ResourcesManager: getTopLevelResources: /data/app/com.alisaki.myblog-2/base.apk / 1.0 running in com.alisaki.myblog rsrc of package com.alisaki.myblog
06-04 10:24:55.594 32201-32201/? W/ResourcesManager: getTopLevelResources: /data/app/com.alisaki.myblog-2/base.apk / 1.0 running in com.alisaki.myblog rsrc of package com.alisaki.myblog
06-04 10:24:55.594 32201-32201/? W/ResourceType: Failure getting entry for 0x01080947 (t=7 e=2375) (error -75)
06-04 10:24:55.644 32201-32201/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
06-04 10:24:55.734 32201-32201/? D/PhoneWindow: *FMB* installDecor mIsFloating : false
06-04 10:24:55.734 32201-32201/? D/PhoneWindow: *FMB* installDecor flags : -2139029248
06-04 10:24:55.744 32201-32201/? I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
06-04 10:24:55.744 32201-32201/? I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$OnUnhandledKeyEventListenerWrapper>
06-04 10:24:56.014 32201-32201/? D/TextView: setTypeface with style : 0
06-04 10:24:56.014 32201-32201/? D/TextView: setTypeface with style : 0
06-04 10:24:56.194 32201-32201/com.alisaki.myblog D/Activity: performCreate Call Injection manager
06-04 10:24:56.194 32201-32201/com.alisaki.myblog I/InjectionManager: dispatchOnViewCreated > Target : com.alisaki.myblog.MainActivity isFragment :false
06-04 10:24:56.214 32201-32222/com.alisaki.myblog D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: false
06-04 10:24:56.224 32201-32201/com.alisaki.myblog D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
06-04 10:24:56.224 32201-32201/com.alisaki.myblog D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
06-04 10:24:56.275 32201-32221/com.alisaki.myblog W/System.err: remove failed: ENOENT (No such file or directory) : /data/data/com.alisaki.myblog/cache/picasso-cache/journal.tmp
06-04 10:24:56.285 32201-32222/com.alisaki.myblog I/OpenGLRenderer: Initialized EGL, version 1.4
06-04 10:24:56.285 32201-32222/com.alisaki.myblog D/OpenGLRenderer: Get maximum texture size. GL_MAX_TEXTURE_SIZE is 4096
06-04 10:24:56.285 32201-32222/com.alisaki.myblog D/OpenGLRenderer: Enabling debug mode 0
06-04 10:24:56.375 32201-32201/com.alisaki.myblog W/art: Before Android 4.1, method int androidx.appcompat.widget.DropDownListView.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
06-04 10:24:56.385 32201-32201/com.alisaki.myblog I/InjectionManager: dispatchCreateOptionsMenu :com.alisaki.myblog.MainActivity
06-04 10:24:56.385 32201-32201/com.alisaki.myblog I/InjectionManager: dispatchPrepareOptionsMenu :com.alisaki.myblog.MainActivity
06-04 10:24:56.405 32201-32201/com.alisaki.myblog I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@25ceb117 time:29711119
06-04 10:25:07.716 32201-32201/com.alisaki.myblog V/ActivityThread: updateVisibility : ActivityRecord{369d2259 token=android.os.BinderProxy@25ceb117 {com.alisaki.myblog/com.alisaki.myblog.MainActivity}} show : true
Build.gradle内容:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.alisaki.myblog"
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:1.0.2"
implementation "androidx.core:core-ktx:1.0.2"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "com.google.android.material:material:1.0.0"
implementation "com.android.volley:volley:1.1.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "de.hdodenhof:circleimageview:3.0.0"
implementation "org.jsoup:jsoup:1.12.1"
implementation "com.squareup.picasso:picasso:2.71828"
implementation "com.github.bumptech.glide:glide:4.9.0"
kapt "com.github.bumptech.glide:compiler:4.9.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
testImplementation "junit:junit:4.12"
testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
}
毕加索未提供任何日志
当我尝试使用Glide时,它也不起作用。我在日志中收到错误:
W/Glide: Load failed for https://1.bp.blogspot.com/-qgZfrkC0FWw/XPWFD8BtcOI/AAAAAAABcs4/S8KFUqFgVtgrmMn5CZ7J8UkKLM1OQ6FVACLcBGAs/s640/Firefox%2BLockwise.jpg with size [389x623]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
There was 1 cause:
java.net.NoRouteToHostException(No route to host)
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 cause:
java.net.NoRouteToHostException(No route to host)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
There was 1 cause:
java.net.NoRouteToHostException(No route to host)
call GlideException#logRootCauses(String) for more detail
Cause (1 of 1): class java.net.NoRouteToHostException: No route to host
I/Glide: Root cause (1 of 1)
java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
at java.net.Socket.connect(Socket.java:605)
at com.android.okhttp.internal.Platform.connectSocket(Platform.java:113)
at com.android.okhttp.Connection.connectSocket(Connection.java:196)
at com.android.okhttp.Connection.connect(Connection.java:172)
at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:367)
at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:130)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.connect(DelegatingHttpsURLConnection.java:89)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:104)
at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:59)
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:65)
at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100)
at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:62)
at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:309)
at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:446)
我正在使用Samsung J3 6 android Lolipop(API 22)
对不起,英语不好
答案 0 :(得分:0)
更新
给出您的imageview的高度和宽度,而不是0dp并删除约束layoutlayout。
在您的Android清单中添加互联网权限
<uses-permission android:name="android.permission.INTERNET" />
我尝试过,并且在Picasso以下版本中都可以正常工作
implementation 'com.squareup.picasso:picasso:2.71828'
答案 1 :(得分:0)
您是否已将Internet权限添加到AndroidManifest.xml
就像。
<uses-permission android:name="android.permission.INTERNET" />
请使用以下方法获取解决方案。
Picasso..with(this)
.load("https://1.bp.blogspot.com/-qgZfrkC0FWw/XPWFD8BtcOI/AAAAAAABcs4/S8KFUqFgVtgrmMn5CZ7J8UkKLM1OQ6FVACLcBGAs/s640/Firefox%2BLockwise.jpg")
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
.into(imageView);