2016-06-01 3 views
0

원하는 행이 들어있는 custom_row.xml을 사용하여 CustomAdapter에서 Arraylist를 호출하고 있습니다. 나는 arraylist의 첫 번째 두 요소를 나란히 나열한 다음 다른 행의 세 번째와 네 번째 요소를 계속 정렬합니다. Arraylist의 첫 번째 요소를 인쇄하기 위해이 코드를 작성했습니다. 주석을 제거한 다음 실행하면 주석을 넣을 때와 같은 오류가 발생합니다. 내가 어디로 잘못 가고 있는지 모르겠다.사용자 지정 어댑터에서 arrayList 전달

또는 올바른 방법이어야합니다. COM에서 null 객체 참조 에 '무효 android.widget.TextView.setText (java.lang.CharSequence)'가상 메서드를 호출하는 시도 :

class CustomAdapter extends ArrayAdapter { 

List<String> names; 
LayoutInflater inflater; 
Context context; 
public CustomAdapter(Context context, List<String> names) { 
    super(context,R.layout.custom_row ,names); 
    this.names=names; 
    this.context=context; 
} 


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


    inflater=LayoutInflater.from(getContext()); 
    View customview=inflater.inflate(R.layout.custom_row,parent,false); 
    String data=names.get(position); 
    //String data1=names.get(position+1); 
    TextView tv=(TextView)customview.findViewById(R.id.TeamA); 
    tv.setText(data); 
    //TextView tv1=(TextView)customview.findViewById(R.id.TeamB); 
    //tv1.setText(data1); 
    return customview; 
} 

나는 점점 오전이 java.lang.NullPointerException이를 오류 - .example.CustomAdapter.getView

+0

R.layout.custom_row에 있는지 확인? – Mohit

답변

1

문제는 tv가 null이기 때문에 findViewById(R.id.TeamA) 반환 널 (null) 때문에, 즉, 그래서 .. 당신이 초기화 된`name` 목록이 TeamA

관련 문제