0

I am developing an application with rest web service. By getting the json response from server, am parsing it and populating it in a custom list view using adapter. In that json response there are url's to download image to display in list items. Every thing has been done and working fine, except loading image from url there is Nullpointer exception. I have done debugging also, logcat shows as follows

    java.lang.NullPointerException
    at android.widget.AbsListView.obtainView(AbsListView.java:2269)
    at android.widget.ListView.measureHeightOfChildren(ListView.java:1244)
    at android.widget.ListView.onMeasure(ListView.java:1156)
    at android.view.View.measure(View.java:15172)
    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:602)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:415)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at android.view.View.measure(View.java:15172)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
    at android.view.View.measure(View.java:15172)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2
    at android.view.View.measure(View.java:15172)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
    at android.view.Choreographer.doFrame(Choreographer.java:525)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4745)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    at dalvik.system.NativeStart.main(Native Method)
    Force finishing activity com.shopping/.views.JsonListView

Can some one help me to find the reason why getting this exception.

Edit:

     int loader = R.drawable.fb_icon;
 // ImageLoader class instance
 ImageLoader imgLoader = new ImageLoader(_Context);


 imgLoader.DisplayImage(imageUrl, loader, holder.productImage);
     public void DisplayImage(String url, int loader, ImageView imageView)
     {  
        stub_id = loader;
        imageViews.put(imageView, url);
        Bitmap bitmap=memoryCache.get(url);
        if(bitmap!=null)
           imageView.setImageBitmap(bitmap);
        else
        {
            queuePhoto(url, imageView);
            imageView.setImageResource(loader);
        }
      }
4
  • 4
    Some source code would be helpfull... Commented Oct 29, 2012 at 12:21
  • @Androholic Please post some code so we can help you more and are you using lazy loading for download and display image in listview. Commented Oct 29, 2012 at 12:25
  • yes, am using lazy loading. and please check the edit Commented Oct 29, 2012 at 12:28
  • @Dipak Yes, tested url and its working fine. Commented Oct 29, 2012 at 12:33

1 Answer 1

1

Write below line into your adapter's getview() method.

imageLoader.DisplayImage(url[position], imageview1);

and see below lazy loading link for more information and if you have any query regarding that then tell me.

Lazy Loading Listview

Sign up to request clarification or add additional context in comments.

2 Comments

am passing arraylist to adapter class that contains 2 strings (1 for text, 2nd for url). Converting that into String array in adapter constructor. and using those strings. how can i use that string like url[position]?
@Androholic Pass this string instead of url[position] and check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.