Hi I am using am developing android application that uses a custom list view, but I keep getting java.lang.ArrayIndexOutOfBoundsException error. Yet I cant find any errors in my code where could I have gone wrong.
public class MainActivity extends Activity {
ListView lv_event;
List<HashMap<String, String>> alist;
String[] event_name = { "The Kampala City Festival",
"The Awakening (Lantern Meet of Poets Recital)" };
int[] event_img = { R.drawable.kla_festival, R.drawable.city_rooming };
String[] event_date = { "October 6th, 2013", "October 4th, 2013" };
String[] event_venue = { "Watoto Church, Central", "National Theatre" };
String[] event_time = { "11:30 am", "07:00 pm" };
String[] event_info = { "The #KampalaCityFestival will on Sunday 6th October",
"From the creators of Broken Voices of the Revolution "
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUI();
setEventList();
}
private void setEventList() {
// TODO Auto-generated method stub
try {
alist = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < 3; i++) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("event_picture", Integer.toString(event_img[i]));
hm.put("event_name", event_name[i]);
hm.put("event_date", event_date[i]);
hm.put("event_venue", event_venue[i]);
hm.put("event_time", event_time[i]);
hm.put("event_info", event_info[i]);
alist.add(hm);
}
// from
String[] from = { "event_picture", "event_name", "event_date",
"event_venue", "event_time", "event_info" };
// to
int[] to = { R.id.img_view_event, R.id.tv_event_name, R.id.tv_date,
R.id.tv_event_place, R.id.tv_time, R.id.tv_event_info };
SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(),
alist, R.layout.lv_custom, from, to);
lv_event.setAdapter(adapter);
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.toString(),
Toast.LENGTH_LONG).show();
}
}
private void setUI() {
// TODO Auto-generated method stub
lv_event = (ListView) findViewById(R.id.lv_event);
}