2016-01-20 57 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' 

並同步您的項目。