【问题标题】:UIL doesn't support scheme(protocol) by defaultUIL 默认不支持方案(协议)
【发布时间】:2016-07-03 10:11:30
【问题描述】:

我在控制台中收到此错误。

UIL doesn't support scheme(protocol) by default ["http://mywebsite.com/mylocation/image.jpg"]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))

我正在尝试将图像从我的网站加载到 Android 应用程序中。 后续步骤: 在 build.gradle 中

dependencies {compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'}

在 AndroidManifest.xml 中

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

这是我得到的 json 输出:

"image":"\"http:\\\/\\\/mywebsite.com\\\/mylocation\\\/image.jpg\""

在我的 ApplicationActivity.java 中

ImageView myImage
myImage = (ImageView)findViewById(R.id.image_id);

我尝试剥离所有不必要参数的 url,如下所示:

 imageUrl = url.replaceAll("\\[]\"", "");
 imageUrl = imageUrl.replace("\\/","/");

这是我用来尝试使用 UniversalImageLoader 加载图像的 ApplicationActivity.java 中的代码:

        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
//
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .defaultDisplayImageOptions(defaultOptions)
                .build();
        ImageLoader.getInstance().init(config); 
Toast.makeText(single_event.this, imageUrl, Toast.LENGTH_LONG).show();
    if(imageUrl != null) {
       //Sets Image
        ImageLoader.getInstance().displayImage(imageUrl, myImage);

    }
  Log.d("URL", imageUrl);

控制台日志和 toast 都返回正确的 url 引号“http://mywebsite.com/mylocation/image.jpg

我错过了一些配置或设置吗? ImageLoader.getInstance().displayImage(imageUrl, myImage); 之后我还有什么需要做的吗?

请帮忙。

[编辑] 这是布局(下图)。如果我将布局中的图像源指定为可绘制图像,则从手机加载图像并忽略所有 Java 逻辑。如果我删除源,那么什么都不会发生 <ImageView android:layout_width="fill_parent" android:layout_height="120dp" android:id="@+id/image_id" android:layout_marginTop="3dp" android:layout_marginBottom="3dp" android:contentDescription="@string/cnt" android:src="@drawable/local_placeholder" />

【问题讨论】:

  • 我认为replaceAll("\\[]\"", "") 中的正则表达式是错误的(它不应该是有效的正则表达式)。你应该写成:replaceAll("[\\\\\"]", "")
  • 您好,我尝试更改它无济于事。也许问题出在布局上?请参阅编辑。
  • 您是否去掉了 URL 中的引号?我的意思是,当您打印它时(在吐司内或 LogCat 中),您能看到引号吗?如果答案是肯定的,那么您需要删除它们。 (这是您问题的第二行所建议的)
  • 是的,引号仍然在吐司和日志中。如何在 java for android 中删除它们?
  • 我认为之前提供的正则表达式应该可以工作

标签: java android-studio universal-image-loader


【解决方案1】:
        imageUrl = imageUrl.substring(1, imageUrl.length()-1);

从“http://mywebsite.com/mylocation/image.jpg”中删除引号解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 2013-09-25
    • 2018-12-03
    • 2020-12-14
    • 2018-06-29
    • 1970-01-01
    相关资源
    最近更新 更多