我正在尝试下载并在我的Android应用程序中将图像加载到我的NetworkImageView ..但我收到此错误
引起:java.lang.NullPointerException:尝试在空对象引用上调用虚方法'com.android.volley.toolbox.ImageLoader com.example.username.socialoid.AppController.getImageLoader()'
不要发生什么事。通常由于声明错误而发生空指针,但我在这里没有犯错..请帮助..
这是我的代码snippiest
// user profile pic
profilePic.setImageUrl(item.getProfilePic(), imageLoader);
和imageloader在其他类中如下
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
public ImageLoader getImageLoader() {
getRequestQueue();
if (mImageLoader == null) {
getLruBitmapCache();
mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
}
return this.mImageLoader;
}
我的LruBitmapCache类
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);
}
}
完成Log ::
11-30 15:35:39.635 27827-27827/com.example.hissamyousaf.socialoid E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.hissamyousaf.socialoid, PID: 27827
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hissamyousaf.socialoid/com.example.hissamyousaf.socialoid.Home}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hissamyousaf.socialoid/com.example.hissamyousaf.socialoid.NewsFeed}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.toolbox.ImageLoader com.example.hissamyousaf.socialoid.AppController.getImageLoader()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hissamyousaf.socialoid/com.example.hissamyousaf.socialoid.NewsFeed}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.toolbox.ImageLoader com.example.hissamyousaf.socialoid.AppController.getImageLoader()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2435)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:776)
at android.widget.TabHost.setCurrentTab(TabHost.java:435)
at android.widget.TabHost.addTab(TabHost.java:262)
at com.example.hissamyousaf.socialoid.Home.onCreate(Home.java:42)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.toolbox.ImageLoader com.example.hissamyousaf.socialoid.AppController.getImageLoader()' on a null object reference
at com.example.hissamyousaf.socialoid.FeedListAdapter.<init>(FeedListAdapter.java:28)
at com.example.hissamyousaf.socialoid.NewsFeed.onCreate(NewsFeed.java:43)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2435)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:776)
at android.widget.TabHost.setCurrentTab(TabHost.java:435)
at android.widget.TabHost.addTab(TabHost.java:262)
at com.example.hissamyousaf.socialoid.Home.onCreate(Home.java:42)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)