mardi 20 janvier 2015

checkbox giving NPE eror in android

Hi In this below code I am creating checkbox array named as checkBoxState.But when I am clicking it's giving NPE In the below code.My activity it will show the usernames with checkbox when I am selecting with check box but it's throwing NPE.


Can any one help me. java



boolean checkBoxState[];
public View getView(final int position, View convertView, ViewGroup parent) {

final ViewHolder holder;


if (convertView == null)
{
convertView = mInflater.inflate(R.layout.grouplist, null);


holder = new ViewHolder();

holder.text = (TextView) convertView.findViewById(R.id.text);
holder.icon = (ImageView) convertView.findViewById(R.id.icon);
holder.check1 = (CheckBox) convertView.findViewById(R.id.checkBox1);

convertView.setTag(holder);

}

else {

holder = (ViewHolder) convertView.getTag();
}


holder.text.setText(friends[position].userName);
holder.icon.setImageBitmap(friends[position].status == STATUS.ONLINE ? mOnlineIcon : mOfflineIcon);

holder.check1.setChecked(checkBoxState[position]);
holder.check1.setOnCheckedChangeListener(new OnCheckedChangeListener(){

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
checkBoxState[position]=isChecked;
}
});


return convertView;
}




Aucun commentaire:

Enregistrer un commentaire