0

I got NullPointerException in line 98 in pastie and equal to line 191 in my locate imageLoader.displayImage((String) myArr.get(position).get("image_url"), imageView, options, new SimpleImageLoadingListener()...

all my url I store it in ArrayList<HashMap<String, Object>>

full code http://pastie.org/7108410#94

Error

    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)
kongkea
  • 9,062
  • 11
  • 37
  • 47

2 Answers2

3

Your ImageLoader imageLoader is always null. You need to initialize it.

Try to replace:

ImageLoader imageLoader;

by

ImageLoader imageLoader = ImageLoader.getInstance();
sdabet
  • 17,379
  • 11
  • 73
  • 143
  • But I declare it already? and How to initialize it and with what? – kongkea Mar 25 '13 at 09:56
  • @kongkea : put `imageLoader.init(ImageLoaderConfiguration.createDefault(ImagePagerActivity.this));` in ImagePagerAdapter constructor – ρяσѕρєя K Mar 25 '13 at 10:04
  • @ρяσѕρєяK that won't work. You need to assign a value to `imageLoader` first, like `ImageLoader imageLoader = new ImageLoader(...);` – sdabet Mar 25 '13 at 10:12
  • @kongkea : see [Universal Image Loader for Android](https://github.com/nostra13/Android-Universal-Image-Loader) and initialize it according to ur need – ρяσѕρєя K Mar 25 '13 at 10:15
  • @fiddler could you please help me? everything in full source code above – kongkea Mar 25 '13 at 10:16
  • see my edit `ImageLoader imageLoader = ImageLoader.getInstance();` – sdabet Mar 25 '13 at 10:18
  • java.lang.IllegalStateException: ImageLoader must be init with configuration before using. @fiddler – kongkea Mar 25 '13 at 10:19
  • the explanation is in the error message. please follow @ρяσѕρєяK's advice and read this: https://github.com/nostra13/Android-Universal-Image-Loader – sdabet Mar 25 '13 at 10:22
1
  1. set a breakpoint in line 98 and verify that imageView is not null.
  2. add a debug log message before line 98 and print out myArr.get(position).get("image_url") to see if this is a valid url and is actually not null.
  3. when you set the breakpoint, verify that imageLoader is not null

As for how to debug in Eclipse, I would suggest looking at this SO question and the answers below

Community
  • 1
  • 1
Lefteris
  • 14,002
  • 2
  • 52
  • 90
  • Did you check for the imageLoader pointer and the imageView pointer? Are they both not null? – Lefteris Mar 25 '13 at 10:28
  • how to check both imageLoader and ImageView? – kongkea Mar 25 '13 at 10:30
  • when you set a breakpoint (you need to run the app in eclipse in debug mode), once eclipse hits the breakpoint it will stop. Put your mouse cursor over the imageView variable and it will display the value it has. Same for the imageLoader – Lefteris Mar 25 '13 at 10:32
  • When I move cursor over the `myArr` and `position` it show me value but I over on imageView it show a lot of items. I don't know which one that show me null image. – kongkea Mar 26 '13 at 06:31