import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; public class StudentAdapter extends ArrayAdapter { Context context; int layoutResourseId; Student data[] = null; public StudentAdapter(Context context, int layoutResourceId, Student[] data) { super(context, layoutResourceId, data); this.context = context; this.layoutResourseId = layoutResourceId; this.data = data; // TODO Auto-generated constructor stub } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; StudentHolder holder = null; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourseId, parent, false); holder = new StudentHolder(); //Associate the Items in the holder with a view in the XML file. holder.tvStNumber = (TextView)row.findViewById(R.id.tvStNumber); row.setTag(holder); } else { holder = (StudentHolder) row.getTag(); } //Setting the text for the items Student item =data[position]; holder.tvStNumber.setText(item.GetStudentNumber()); return row; } //Student Holder static class StudentHolder { TextView tvStNumber; TextView tvStDescription; } } listView1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position,long id) { try{ String listValue = ((TextView)view).getText().toString(); //This is where the exception is happening. The below text should have been commented out. // String text = (String) listView1.getItemAtPosition(position); // this is where the excexption is happening. Toast.makeText(getApplicationContext(), "You click" + position, Toast.LENGTH_LONG).show(); String d = "Test toast."; }catch(Exception e) { Log.e("Error Message", e.getMessage()); } } }); ?xml version="1.0" encoding="utf-8"?> String listValue = (((TextView) ((RelativeLayout) v).getChildAt(0)).getText().toString()); String listValue = ((TextView)view).getText().toString(); listView1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position,long id) { try{ String listValue = parent.getItemAtPosition(position).GetStudentNumber(); //This is where the exception is happening. The below text should have been commented out. // String text = (String) listView1.getItemAtPosition(position); // this is where the excexption is happening. Toast.makeText(getApplicationContext(), "You click" + position, Toast.LENGTH_LONG).show(); String d = "Test toast."; }catch(Exception e) { Log.e("Error Message", e.getMessage()); } } });