我的NetworkView
出现问题,我正在尝试在我的应用中加载图片,图片网址来自我的localhost 127.0.0.1。但它似乎不起作用我只看到networkView.setDefaultImage
。
来自logcat的<{1}}输出:
这是'我的代码:JSON
LruCacheMap.java
这是我的public class LruCacheMap extends LruCache<String,Bitmap> implements ImageLoader.ImageCache{
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
//CONSTRUCTOR
public LruCacheMap(){
//put the method
this(getDefaultLruCacheSize());
}
//EQUIVALENT SIZE IN Kb
public LruCacheMap(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);
} }
OrgListAdapter.java
这是我的控制器 - @Override
public void onBindViewHolder(OrgViewHolder holder, int position) {
if (mOrganizationData.get(position).getOrgType().equalsIgnoreCase("Public")){
holder.appCompatImageViewOrgType.setImageResource(R.drawable.ic_type_public);
}else {
holder.appCompatImageViewOrgType.setImageResource(R.drawable.ic_action_private_group);
}
//IMAGE LOADER orgLogoName
if (imageLoader == null) {
imageLoader = SingletonController.getInstance().getImageLoader();
Log.e("ImageLoader Problem",imageLoader+"");
}
orgLogoName = mOrganizationData.get(position).getOrgLogoName();
orgLogoPath = mOrganizationData.get(position).getOrgLogoPath();
logoUrl = orgLogoPath + orgLogoName;
holder.networkImageViewLogo.setDefaultImageResId(R.drawable.picture_32px);
if (logoUrl != null){
Log.e("The URL: ", logoUrl);
holder.networkImageViewLogo.setBackgroundColor(GetColorSdk.getColor(mContext,R.color.appIntroColorFifth));
holder.networkImageViewLogo.setImageUrl(logoUrl,imageLoader);
}else{
holder.networkImageViewLogo.setErrorImageResId(R.drawable.picture_32px);
}
}
SingletonController.java
我尝试调试,它表明它不是null。 我想在public class SingletonController extends Application{
public static final String TAG = SingletonController.class.getSimpleName();
public Context mContext;
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
LruCacheMap mLruBitmapCache;
private static SingletonController mInstance;
public SingletonController(){}
public SingletonController(Context context){
this.mContext = context;
}
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized SingletonController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public ImageLoader getImageLoader() {
//REQUEST QUEUE
getRequestQueue();
if (mImageLoader == null) {
getLruBitmapCache();
mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
}
return this.mImageLoader;
}
public LruCacheMap getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruCacheMap();
return this.mLruBitmapCache;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
} }
。
注意:我使用此one将笔记本电脑作为hospot,然后获取networkImage
。我的笔记本电脑用作服务器。我正在使用模拟器ipV4
和实际设备。
在我的url代码中:(Geny Motion)