关于这个花了好一个晚上的时间最后还是没有解决,个人觉得应该没有什么问题可是就是有问题..
贴上源码: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什么的都获得布局里的对象了的。大家帮忙看下,感谢...
贴上源码: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什么的都获得布局里的对象了的。大家帮忙看下,感谢...
解决方案 »
- Android下OpenGL贴图的问题
- 动态填充TableLayout,如何让表格充满屏幕?如何设置动态生成的Textview的字体大小?
- marvll 8787三合一模块移植 wifi和蓝牙不能同时用?
- Android 程序出错 出现main.out.xml
- android 怎样在状态栏添加选项卡
- android中如何创建自己的收件箱
- 怎么能够获取手机相机支持的分辨率?
- ActionBar移动到界面底部
- android如何用返回栈分批管理fragment,我的软件只有一个activity,也就只有一个返回栈
- android canvas 画图
- 怎么把文件流变成的字符串变回文件?
- 请问下,这种控件比较专业的叫法是什么,Android中如何实现
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
{
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;
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()方法里的问题