I'm trying to fetch values from listView with a for loop and put them in a hashmap. but the logcat keeps throwing this error. I can't figure out why. Any help please! the list view has @android:id/list and I have extended ListActivity on my activity here is my code to fetch those values
listStudent=getListView(); studentMarksList=new ArrayList<HashMap<String,String>>(); String student,obtained_value,max_value; for (int i=0;i<listStudent.getCount();i++) { View view=listStudent.getChildAt(i); studentIdTxt=(TextView) view.findViewById(R.id.student_id_ls); obtainedTxt=(EditText) view.findViewById(R.id.obtained); maxTxt=(TextView) view.findViewById(R.id.max); student=studentIdTxt.getText().toString(); obtained_value=obtainedTxt.getText().toString(); max_value=maxTxt.getText().toString(); //updating the new mark list array HashMap<String,String>studentMark=new HashMap<String,String>(); studentMark.put(TAG_STUDENT_ID,student); studentMark.put(TAG_MARKS_OBTAINED,obtained_value); studentMark.put(TAG_MARKS_MAX,max_value); studentMarksList.add(studentMark); }
And here is my xml layout for the list
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@android:id/list" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="106dp" />
and here is the xml for list items
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/student_name_ls" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip" android:paddingTop="6dip" android:textColor="#1e5401" android:textSize="16sp" android:textStyle="bold" /> <!-- Marks label --> <EditText android:id="@+id/obtained" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#acacac" android:inputType="numberDecimal" android:numeric="decimal" /> <TextView android:id="@+id/max" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#0b0b0b" android:enabled="false" android:editable="false" /> <TextView android:id="@+id/student_id_ls" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="2dip" android:textColor="#060606" android:visibility="gone" /> </LinearLayout>
And the problem is on this line "studentIdTxt=(TextView) view.findViewById(R.id.student_id_ls);" throws nullpointerexception any help please
No comments:
Post a Comment