0

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

我所有的网址都存储在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)
4

2 回答 2

3

ImageLoader imageLoader的总是空的。你需要初始化它。

尝试替换:

ImageLoader imageLoader;

经过

ImageLoader imageLoader = ImageLoader.getInstance();
于 2013-03-25T09:53:13.987 回答
1
  1. 在第 98 行设置断点并验证 imageView 不为空。
  2. 在第 98 行之前添加调试日志消息并打印出 myArr.get(position).get("image_url") 以查看这是否是有效的 url 并且实际上不为空。
  3. 设置断点时,验证 imageLoader 不为空

至于如何在 Eclipse 中调试,我建议看看这个 SO question和下面的答案

于 2013-03-25T10:19:04.257 回答