NullPointerException发生在某些列表项中

时间:2018-08-07 08:22:29

标签: android json listview bitmap nullpointerexception

我的应用程序中有一个自定义列表视图,该列表视图由JSON填充,并且我正在使用位图在listView中填充图像,我想在已单击的列表项中获取TextView值

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();
    }
  }
});

,它适用于列表的前两个项目,但对于另一个项目,应用程序将在hotel_id定义行上停止,当我单击除前两个项目以外的其他项目时,这是logcat:

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)

问题是列表的所有项目ID都将TextView强制转换为一个ID,但是对于“某些”项目而言,ID为null 有谁知道这是什么问题吗?

0 个答案:

没有答案