通用图像加载器 - imageloader.displayimage中的Viewpager NullPointerException

时间:2013-03-25 09:45:20

标签: android url arraylist android-viewpager universal-image-loader

我在pastie的第98行中得到了NullPointerException,并且在我的locate imageLoader.displayImage((String) myArr.get(position).get("image_url"), imageView, options, new SimpleImageLoadingListener()..中等于第191行。

我将所有网址存储在ArrayList<HashMap<String, Object>>

完整代码http://pastie.org/7108410#94

错误

    03-25 16:39:33.382: E/AndroidRuntime(18178): FATAL EXCEPTION: main
03-25 16:39:33.382: E/AndroidRuntime(18178): java.lang.NullPointerException
03-25 16:39:33.382: E/AndroidRuntime(18178):    at com.camitss.phnompenhcafe.ImagePagerActivity$ImagePagerAdapter.instantiateItem(ImagePagerActivity.java:191)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:801)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.support.v4.view.ViewPager.populate(ViewPager.java:930)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1366)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.View.measure(View.java:15479)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.View.measure(View.java:15479)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.View.measure(View.java:15479)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.View.measure(View.java:15479)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.View.measure(View.java:15479)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2359)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.View.measure(View.java:15479)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1966)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1212)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1385)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1105)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4452)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.Choreographer.doFrame(Choreographer.java:525)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.os.Handler.handleCallback(Handler.java:615)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.os.Looper.loop(Looper.java:137)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at android.app.ActivityThread.main(ActivityThread.java:4895)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at java.lang.reflect.Method.invokeNative(Native Method)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at java.lang.reflect.Method.invoke(Method.java:511)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
03-25 16:39:33.382: E/AndroidRuntime(18178):    at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:3)

您的ImageLoader imageLoader始终为空。你需要初始化它。

尝试替换:

ImageLoader imageLoader;

通过

ImageLoader imageLoader = ImageLoader.getInstance();

答案 1 :(得分:1)

  1. 在第98行设置断点并验证imageView不为空。
  2. 在第98行之前添加调试日志消息并打印出myArr.get(position).get(“image_url”)以查看这是否是一个有效的URL并且实际上不是null。
  3. 设置断点时,验证imageLoader是否为空
  4. 至于如何在Eclipse中调试,我建议查看this SO question和下面的答案