Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在android中设置customListView?_Java_Android_Listview_Nullpointerexception_Android Arrayadapter - Fatal编程技术网

Java 如何在android中设置customListView?

Java 如何在android中设置customListView?,java,android,listview,nullpointerexception,android-arrayadapter,Java,Android,Listview,Nullpointerexception,Android Arrayadapter,我一直在遵循一个教程,但我认为它已经过时了,我已经设置了listView工作所需的一切,但当我运行它时,它说- java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference

我一直在遵循一个教程,但我认为它已经过时了,我已经设置了listView工作所需的一切,但当我运行它时,它说-

 java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
                                                   at youknow.smscontrol.jason.testexpandiblelistview.CoustmListViewSettup.getView(CoustmListViewSettup.java:29)
以下是我的XML:

这是我的customListViewSetup类:

 class CustomListViewSetup extends ArrayAdapter<String>{

public CustomListViewSetup(Context context, String[] CMDList){
    super(context,R.layout.coustom_list_item ,CMDList);
}

@Override
public View getView(int position, View convertView, ViewGroup parent){

    LayoutInflater CMDlistInflater = LayoutInflater.from(getContext());
    View coustomView = CMDlistInflater.inflate(R.layout.coustom_list_item, parent, false);

    String CurrentCMDlistitem = getItem(position);
       LINE 29>> TextView CMDlist = (TextView) convertView.findViewById(R.id.CMDnameItem);
    ImageView CMDLaunchArrow = (ImageView) convertView.findViewById(R.id.LaunchArrow);

    CMDlist.setText(CurrentCMDlistitem);
    CMDLaunchArrow.setBackgroundResource(R.drawable.item_launch);




    return coustomView;
}
 }
class CustomListViewSetup扩展了ArrayAdapter{
公共CustomListViewSetup(上下文上下文,字符串[]CMDList){
超级(上下文,R.layout.coustom\u列表项,CMDList);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutInflater CMDlistInflater=LayoutInflater.from(getContext());
View-coustomView=CMDlistInflater.inflate(R.layout.coustom\u列表\u项,父项,false);
字符串CurrentCMDlistitem=getItem(位置);
第29行>>TextView CMDlist=(TextView)convertView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow=(ImageView)convertView.findViewById(R.id.LaunchArrow);
CMDlist.setText(CurrentCMDlistitem);
CMDLaunchArrow.setBackgroundResource(R.drawable.item_launch);
返回视图;
}
}
提前谢谢你

LayoutInflater CMDlistInflater = LayoutInflater.from(getContext());
View coustomView = CMDlistInflater.inflate(R.layout.coustom_list_item, parent, false);
拆下此线路

更换线路

 TextView CMDlist = (TextView) convertView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow = (ImageView) convertView.findViewById(R.id.LaunchArrow);

LayoutInflater CMDlistInflater = LayoutInflater.from(getContext());
View coustomView = CMDlistInflater.inflate(R.layout.coustom_list_item, parent, false);
 TextView CMDlist = (TextView) convertView.findViewById(R.id.CMDnameItem);
ImageView CMDLaunchArrow = (ImageView) convertView.findViewById(R.id.LaunchArrow);
 TextView CMDlist = (TextView) coustomView.findViewById(R.id.CMDnameItem);
    ImageView CMDLaunchArrow = (ImageView) coustomView.findViewById(R.id.LaunchArrow);