2013-01-17 7 views
0

사용자 지정 배열 어댑터를 사용하여 연락처 목록을 표시하려고했습니다. com.example.contactsapp.ContactsListAdapter.getView (ContactsListAdapter.java:37)에서사용자 지정 목록 어댑터에서 Null 포인터 예외가 발생했습니다.

java.lang.NullPointerException이

이 내 사용자 정의 목록이다 : 그러나 나는 내 응용 프로그램을 실행할 때마다 나는 다음과 같은 오류가 발생합니다 어댑터 클래스 :

:

public class ContactsListAdapter extends ArrayAdapter<Contact> { 

List <Contact> people; 
//Contact c; 
TextView name; 
TextView email; 

public ContactsListAdapter(Context context, List<Contact> people) { 
    super(context, R.layout.list_row, people); 
    this.people = people; 

} 

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

    View v = convertView; 

    if(v == null){ 
     LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     inflater.inflate(R.layout.list_row, null); 
    } 

    Contact c = this.people.get(position); 

    name = (TextView)v.findViewById(R.id.namebox); 
    name.setText(c.getName()); 

    email = (TextView)v.findViewById(R.id.emailbox); 
    email.setText(c.getEmail()); 

    return v; 
} 

}

이 내 ListView에 활동이다

}

아이디어가 있으십니까?

+1

줄 37은 무엇입니까? – petey

답변

1

(당신의 로그 캣 오류를 보지 않고 내 기본 가정) 너 때문에

당신은보기를 팽창하지만 View v에 할당되지 않은

v = inflater.inflate(R.layout.list_row, null); 

뭔가 같은

View v = convertView; 

    if(v == null){ 
     LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     v = inflater.inflate(R.layout.list_row, null); 
    } 

를 잊어 버렸습니다. 그래서 NullPointerExceptionnameemail TextViews에 가져 오는 것입니다.

+0

감사합니다. 문제를 해결했습니다. – Javacadabra

관련 문제