2016-03-04 5 views
1
@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    if(convertView == null){ 
     LayoutInflater inflater=(LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView=inflater.inflate(R.layout.program_list,null); 
    } 
    // GET VIEWS 
    TextView nameTxt=(TextView) convertView.findViewById(R.id.nametxt); 
    TextView landTxt=(TextView) convertView.findViewById(R.id.landtxt); 
    TextView groesseTxt=(TextView) convertView.findViewById(R.id.groessetxt); 
    TextView gewichtTxt=(TextView) convertView.findViewById(R.id.gewichttxt); 
    ImageView img =(ImageView) convertView.findViewById(R.id.imageView1); 

    //SET DATA 
    nameTxt.setText(names[position]); 
    landTxt.setText(land[position]); 
    groesseTxt.setText(groesse[position]); 
    gewichtTxt.setText(gewicht[position]); 
    img.setImageResource(images[position]); 

    return convertView; 
} 

I can't start my program of the NullPointerExceptionандроид TextView.setText NullPointer Exception (андроида новичок)

enter image description here

Я хочу, чтобы создать пользовательский элемент управления ListView, с OnClick на новую операцию ...

+2

Один из этих 'nameTxt'' landTxt' 'groesseTxt'' gewichTxt' является нулевым – Bhargav

+0

Какая строка выдает исключение? –

+1

Проблема, вероятно, в том, что один из ваших массивов имеет значение null – victorantunes

ответ

0

отлаживать этот код:

TextView nameTxt=(TextView) convertView.findViewById(R.id.nametxt); 
TextView landTxt=(TextView) convertView.findViewById(R.id.landtxt); 
TextView groesseTxt=(TextView) convertView.findViewById(R.id.groessetxt); 
TextView gewichtTxt=(TextView) convertView.findViewById(R.id.gewichttxt); 
ImageView img =(ImageView) convertView.findViewById(R.id.imageView1); 

Может быть, они просмотры (nametxt,landtxt,groessetxt,gewichttxt,imageView1) не существует в program_list макета.

0

проверить ваши layout (R.layout.program_list), если содержат идентификатор natetxt, landtxt, groessetxt и gewichttxt, вероятно, это ошибка, в строке 98 отсутствует.

, если все существуют, другое - это некоторый массив, содержащий нулевые значения.

0

Одно или несколько ваших текстовых просмотров не принадлежат вашему расположению. Убедитесь, что вы предоставили те же идентификаторы в своем файле макета.