I have a custom listview in my app which fills by JSON and I'm using bitmap to fill images in listView and I want to get a TextView value inside the list item that has been clicked
lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try {
hotel_id = (int) adapterView.getItemIdAtPosition(i);
TextView id= (TextView) lView.getChildAt(i).findViewById(R.id.aNametxt);
type_id_post = deleteIcon.getText().toString();
backgroundTask = new BackgroundTask(textView);
backgroundTask.execute();
Intent intent = new Intent(RoomList.this, RoomPopUp.class);
startActivity(intent);
}
catch (RuntimeException e){
e.printStackTrace();
}
}
});
and it works for the first two items of the list but for another item app will stop on hotel_id definition line and this is logcat when I click an item except for the first two items :
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: java.lang.NullPointerException
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at com.test.RoomList$1.onItemClick(RoomList.java:126)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.widget.AdapterView.performItemClick(AdapterView.java:299)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.widget.AbsListView.performItemClick(AbsListView.java:1158)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.widget.AbsListView$PerformClick.run(AbsListView.java:2957)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.widget.AbsListView$3.run(AbsListView.java:3849)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.os.Looper.loop(Looper.java:136)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5105)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
08-07 11:43:36.026 14747-14747/com.moalem.khane.khanemoalem W/System.err: at dalvik.system.NativeStart.main(Native Method)
the point is all item's id TextView of the list are casting to one id but it for "SOME" items that id is null is there anyone who knows what is the problem of this?