0

我正在开发一个带有休息网络服务的应用程序。通过从服务器获取 json 响应,解析它并使用适配器将其填充到自定义列表视图中。在该 json 响应中有用于下载图像以显示在列表项中的 url。一切都已完成并且工作正常,除了从 url 加载图像存在 Nullpointer 异常。我也调试过,logcat显示如下

    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

有人可以帮我找出出现此异常的原因。

编辑:

     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

1 回答 1

1

将以下行写入适配器的 getview() 方法。

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

并查看下面的延迟加载链接以获取更多信息,如果您对此有任何疑问,请告诉我。

延迟加载列表视图

于 2012-10-29T12:36:28.160 回答