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

enter image description here

I want to create a custom listview, with a onClick to a new Activity...

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
J.Li
  • 13
  • 2

3 Answers3

0

check your layout (R.layout.program_list) if contain the id nametxt, landtxt, groessetxt and gewichttxt probably this is the error, someone is missing in the line 98.

if all exist, the other thing is some array contain null values.

0

debug this code:

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);

Maybe they views (nametxt,landtxt,groessetxt,gewichttxt,imageView1) dont exist in program_list layout.

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
0

One or more of your textviews are not belongs to your layout. Make sure you have provided same ids in your layout file.

Brijesh Chopda
  • 195
  • 2
  • 11