关于这个花了好一个晚上的时间最后还是没有解决,个人觉得应该没有什么问题可是就是有问题..
贴上源码:class CommentAdapter extends BaseAdapter{  public  CommentAdapter(){
  Log.d("Infor", comment_list.size()+"");

   }
@Override
public int getCount() {
// TODO Auto-generated method stub
return comment_list.size();
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return comment_list.get(position);
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
} @Override
public View getView(int position, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
LayoutInflater layoutInflater = LayoutInflater.from(Comment.this);//从当前上下文得到LayoutInflater
rowView = rowViews.get(position);
if(rowView!=null){
rowView=layoutInflater.inflate(R.layout.comment_item, null);
TextView comment_name = (TextView) rowView.findViewById(R.id.comment_item_name);
TextView comment_time = (TextView) rowView.findViewById(R.id.comment_item_time);
TextView comment_text = (TextView) rowView.findViewById(R.id.comment_item_text);
comment_name.setText(comment_list.get(position).get("comment_user_name"));
        comment_time.setText(comment_list.get(position).get("create_time"));
comment_text.setText(comment_list.get(position).get("comment_text"));

rowViews.put(position, rowView);
}
return rowView;
}
   
   }
CommentAdapter adapter=new CommentAdapter();
comment_listview.setAdapter(adapter); 其中CommentAdapter是个内部类,comment_list是个列表List<Map>该值验证确认无误的...
可是最后列表根本就没有显示出来,还报空指针异常。我就纳闷了,没有空指针啊,comment_list什么的都获得布局里的对象了的。大家帮忙看下,感谢...

解决方案 »

  1.   


    08-09 09:58:37.069: ERROR/AndroidRuntime(9801): FATAL EXCEPTION: main
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801): java.lang.NullPointerException
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.AbsListView.obtainView(AbsListView.java:1437)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.ListView.makeAndAddView(ListView.java:1745)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.ListView.fillDown(ListView.java:670)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.ListView.fillFromTop(ListView.java:727)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.ListView.layoutChildren(ListView.java:1598)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.AbsListView.onLayout(AbsListView.java:1265)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.view.View.layout(View.java:7212)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.view.View.layout(View.java:7212)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.view.View.layout(View.java:7212)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.view.View.layout(View.java:7212)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.os.Looper.loop(Looper.java:130)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at android.app.ActivityThread.main(ActivityThread.java:3683)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at java.lang.reflect.Method.invoke(Method.java:507)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    08-09 09:58:37.069: ERROR/AndroidRuntime(9801):     at dalvik.system.NativeStart.main(Native Method)
    贴上保存Log
      

  2.   

    rowViews是什么东东,没看到实例化啊,而且这个地方为什么要这么写?listView本身就有缓存,为什么好用rowViews来缓存?
      

  3.   

    getView里面要改:if (arg1 == null)
    {
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      arg1 = inflater.inflate(R.layout.comment_item, parent, false);
    }TextView comment_name = (TextView) arg1.findViewById(R.id.comment_item_name);
                TextView comment_time = (TextView) arg1.findViewById(R.id.comment_item_time);
                TextView comment_text = (TextView) arg1.findViewById(R.id.comment_item_text);
                comment_name.setText(comment_list.get(position).get("comment_user_name"));
                    comment_time.setText(comment_list.get(position).get("create_time"));
                comment_text.setText(comment_list.get(position).get("comment_text"));return arg1;
      

  4.   

    楼主你的adapter里面没有list数据的,所以不会显示,在构造方法中,传一个list
      

  5.   

     @Override
        public View getView(int position, View arg1, ViewGroup arg2) {
            // TODO Auto-generated method stub
            LayoutInflater layoutInflater = LayoutInflater.from(Comment.this);//从当前上下文得到LayoutInflater
            if(rowView==null){
                rowView=layoutInflater.inflate(R.layout.comment_item, null);
            }
            //rowView = rowViews.get(position);
           // if(rowView!=null){
                rowView=layoutInflater.inflate(R.layout.comment_item, null);
                TextView comment_name = (TextView) rowView.findViewById(R.id.comment_item_name);
                TextView comment_time = (TextView) rowView.findViewById(R.id.comment_item_time);
                TextView comment_text = (TextView) rowView.findViewById(R.id.comment_item_text);
                comment_name.setText(comment_list.get(position).get("comment_user_name"));
                    comment_time.setText(comment_list.get(position).get("create_time"));
                comment_text.setText(comment_list.get(position).get("comment_text"));        
            
                rowViews.put(position, rowView);        
            //}
        return rowView;
        }
    总的 getView()方法里的问题
      

  6.   

    谢谢楼上各位热心回答,已经解决了。应该是rowview==null的时候对它进行处理的。一直没注意到这点。呵呵》。