为什么Android中的凌空无法找到ImageLoader

时间:2016-01-20 11:36:01

标签: java android android-volley

我绝对是Android的初学者。现在我开始使用凌空来进行Http请求和图像缓存。所以从这个链接下载volley.jar - http://api.androidhive.info/volley/volley.jar。然后我把它放在libs库中。然后我按照教程编写了一个用于缓存的类。

我的图片缓存类

package com.example.newfeeds.volley;
import com.android.volley.toolbox.ImageLoader.ImageCache;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

public class LruBitmapCache extends LruCache<String, Bitmap> implements
        ImageCache {
    public static int getDefaultLruCacheSize() {
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
        final int cacheSize = maxMemory / 8;

        return cacheSize;
    }

    public LruBitmapCache() {
        this(getDefaultLruCacheSize());
    }

    public LruBitmapCache(int sizeInKiloBytes) {
        super(sizeInKiloBytes);
    }

    @Override
    protected int sizeOf(String key, Bitmap value) {
        return value.getRowBytes() * value.getHeight() / 1024;
    }

    @Override
    public Bitmap getBitmap(String url) {
        return get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        put(url, bitmap);
    }
}

但它一直说在导入命名空间时无法解析符号ImageLoader。

我的项目结构截图如下。

enter image description here

我正在学习本教程。 http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/

3 个答案:

答案 0 :(得分:2)

已更新: 只需将其粘贴到您的build.gradle应用模块中

implementation 'com.android.volley:volley:1.1.0'

并同步您的项目。

答案 1 :(得分:1)

我遇到了类似的问题。 只需将其粘贴到build.gradle应用程序模块

即可
{{1}}

并同步您的项目。

答案 2 :(得分:0)

我复制粘贴了一个项目,我也遇到了同样的错误,我从 build -> 重建项目重建了我的项目,在使用“alt+enter”进行了一些导入后,错误消失了。