xiaohuihui183 2015-04-25 10:23 采纳率: 0%
浏览 2231

cursor空指针异常,调试不过啊

public class MainActivity extends ActionBarActivity implements OnClickListener{

//private NotesDB notesDB;
//private SQLiteDatabase dbWriter;
private Button textbtn,imgbtn,videobtn;
private ListView lv;
private Intent i;
private MyAdapter adapter;
private NotesDB notesDB;
private SQLiteDatabase dbReader;
public Cursor cursor;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();

    /*notesDB = new NotesDB(this);
    dbWriter = notesDB.getWritableDatabase();
    //addDB();*/
}

public void initView(){
    lv = (ListView) findViewById(R.id.list);
    textbtn = (Button) findViewById(R.id.text);
    imgbtn = (Button) findViewById(R.id.img);
    videobtn = (Button) findViewById(R.id.video);
    textbtn.setOnClickListener(this);
    imgbtn.setOnClickListener(this);
    videobtn.setOnClickListener(this);
    notesDB = new NotesDB(this);
    dbReader = notesDB.getReadableDatabase();
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub
            cursor.moveToPosition(position);
            Intent i = new Intent(MainActivity.this,SelectAct.class);
            i.putExtra(NotesDB.ID, cursor.getInt(cursor.getColumnIndex(NotesDB.ID)));
            i.putExtra(NotesDB.CONTENT, cursor.getString(cursor.getColumnIndex(NotesDB.CONTENT)));
            i.putExtra(NotesDB.TIME, cursor.getString(cursor.getColumnIndex(NotesDB.TIME)));
            i.putExtra(NotesDB.PATH, cursor.getString(cursor.getColumnIndex(NotesDB.PATH)));
            i.putExtra(NotesDB.VIDEO,cursor.getString(cursor.getColumnIndex(NotesDB.VIDEO)));
            startActivity(i);
        }
    });
}

  • 写回答

2条回答 默认 最新

  • danielinbiti 2015-04-25 13:00
    关注

    没有看到打开cursor过程,看一下是否打开了cursor,是否打开后又关闭了。

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类