2016-01-20 56 views
2

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

我的图像缓存类

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/

+0

可能是'jar'文件的问题。尝试通过'Gradle'而不是jar'compile'添加排除。com.mcxiaoke.volley:library:1.0.19'' –

+0

它现在正在工作。我刚关闭了Android工作室并再次打开它。它是如此有线。 –

回答

1

我正面临类似的问题。 只需粘贴您的build.gradle应用模块

compile 'com.android.volley:volley:1.0.0' 

并同步您的项目。