I have a listbox where I choose the elements I want to download by a checkbox, and a FloatingActionButton to confirm. The problem is that on my phone(Android 5.0.2) I get a "Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference" On my tablet (Nexus7 Android 6.0) everything works!
FloatingActionButtonDone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int j = 0; j < ListActivityListView.getCount(); j++) {
v = ListActivityListView.getChildAt(j);
//Here im having troubles!
ck = (CheckBox) v.findViewById(R.id.ListActivityCheckBox);
if (ck.isChecked()) {
/*
Stuff to download ++
*/
}
}
/*
Here I have the code to download my stuff
*/
}//End of onClick
});//End of FloatingActionButtonDone.setOnClickListener
Where: - ck is a CheckBox ck, declared in my class variables. - ListActivityListView is the ListView inside my activity.
I repeat same code works on my tablet, but doesn't on my phone. So i have literally no idea. Since my project is composed by 12 classes, I tried to post here the relevant code I'm having trouble with.
Adapter:
public class ListActivityAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Characters> characters;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();
public ListActivityAdapter(Activity activity, List<Characters> personaggi) {
this.activity = activity;
this.characters = personaggi;
}
@Override
public int getCount() {
return characters.size();
}
@Override
public Object getItem(int location) {
return characters.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.list_drawer_item, null);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.ListActivityCheckBox);
NetworkImageView Immagine = (NetworkImageView) convertView.findViewById(R.id.ListActivityImage);
TextView Nome = (TextView) convertView.findViewById(R.id.ListActivityTitle);
TextView Peso = (TextView) convertView.findViewById(R.id.ListActivitySize);
Characters p = characters.get(position);
Immagine.setImageUrl(p.getImage(), imageLoader);
Nome.setText(p.getName());
Peso.setText(p.getSize());
return convertView;
}
}