Hi i am creating a custom listview with texview ,imageview and i am accessing the data from sqlite database where i am storing name of each image and placing the images in assests folder when i try access it using the holder.mimage.setImageResource(list.get(position).getImage());
it is giving the error how can i access it any suggestion will be very helpfull
public class InteractiveArrayAdapter extends ArrayAdapter<PosHolder> {
String tag = "Events";
private final List<PosHolder> list;
private final Activity context;
int li,jh;
public InteractiveArrayAdapter(Activity context, List<PosHolder> list) {
super(context, R.layout.row, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox,checkbox1;
protected RadioGroup mgroup;
protected RadioButton mbutton;
protected ImageView mimage;
}
public View getView( final int position, View convertView, ViewGroup parent) {
//Log.d(tag," 3");
View view =null;
if (convertView == null) {
//System.out.println("ok");
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.row, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.textView1);
viewHolder.mimage = (ImageView) view.findViewById(R.id.imageView1);
view.setTag(viewHolder);
viewHolder.mimage.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).mimage.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
view.getTag()).mgroup.getTag();
holder.text.setText(list.get(position).getName());
holder.mimage.setImageResource(list.get(position).getImage());//This line is showing the error
return view;
}
public class PosHolder {
private String name;
private String smallimage;
public PosHolder(String name, String smallimage) {
// TODO Auto-generated constructor stub
this.name=name;
this.smallimage=smallimage;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return smallimage;
}
public void setImage(String phone) {
this.smallimage = phone;
}}
It’s becoz you are passing name of image to the imageView not the IMAGE. you are retrving imageName instand of image from the list of PosHolder object. Your PosHolder object giving you string not the image
this is causing exception.