yue1liang1chuan 2013-06-07 07:16 采纳率: 0%
浏览 2376
已采纳

SimpleCursorAdapter错误

在异步任务中添加SimpleCursorAdapter 时出现错误。

private class LoadNewsLists extends AsyncTask<String, Void, Cursor> {
     @Override
     protected void onPreExecute() {         
     }


     @Override
     protected Cursor doInBackground(final String... args) {
         Cursor cursor = dbHelper.fetchMainActivity();
         return cursor;
     }


     protected void onPostExecute(final Cursor cursor) {
         String[] columns = new String[] {
                  DatabaseUtil.rtitle,
                  DatabaseUtil.rtypeof
          };

          // the XML defined views which the data will be bound to
          int[] to = new int[] {
            R.id.idTitle,
            R.id.idType
          };

          // create the adapter using the cursor pointing to the desired data
          //as well as the layout information
          dataAdapter = new SimpleCursorAdapter(
            MainActivity.this, R.layout.listhome,
            cursor,
            columns,
            to,
            0);

          listView = (ListView) findViewById(R.id.list);
          listView.setAdapter(dataAdapter);          
     }

然后出现这些错误:

06-07 09:14:33.496: E/AndroidRuntime(21735): Caused by: java.lang.NullPointerException
06-07 09:14:33.496: E/AndroidRuntime(21735):    
at com.ppshein.test.MainActivity$LoadNewsLists.doInBackground(MainActivity.java:38)
  • 写回答

3条回答 默认 最新

  • kity 2013-06-07 08:54
    关注

    检查下在你返回dbHelper.fetchMainActivity()之前是否调用了cursor.close()方法,或者你取到的cursor就是null

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名