Android数据库cursor.getString()崩溃

时间:2017-07-13 15:19:22

标签: android

我在使用getString()从数据库的第三列获取信息时遇到问题; 当我设置从第二列获取信息时一切正常,但在第三列应用程序崩溃。 以下是第二列的代码,即正在运行的代码:

    Cursor data = myDB.getData();
    ArrayList<String> listData = new ArrayList<>();
    while(data.moveToNext()){
        //get the value from the database in column 1
        //then add it to the ArrayList
        listData.add(data.getString(1));
     //create the list adapter and set the adapter
    ListAdapter adapter = new ArrayAdapter<>(this, 
    android.R.layout.simple_list_item_1, listData);
    listView.setAdapter(adapter);

此列中存储的信息取自EditText字段。

其他代码无效:

    //get the data and append to a list
    Cursor data = myDB.getData();
    ArrayList<String> listData = new ArrayList<>();
    while (data.moveToNext()) {
        //get the value from the database in column 1
        //then add it to the ArrayList
        listData.add(data.getString(2));
    }
    //create the list adapter and set the adapter
    ListAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, listData);
    listView.setAdapter(adapter);

第三栏中存储的内容是:

private String date;

date = getDate();

private String getDate() {
    SimpleDateFormat currentDate = new SimpleDateFormat("dd/MM/yyyy");
    Date todayDate = new Date();
    String thisDate = currentDate.format(todayDate);
    return thisDate;
}

如果我像getString(0)一样更改第二个getString(2)应用程序正在运行; 提前谢谢!

Logcat错误

  

07-13 15:26:15.431:W / ls(5674):type = 1400 audit(0.0:301):avc:denied {getattr} for path =“/ ueventd.rc”dev =“rootfs”ino = 4003 scontext = u:r:shell:s0 tcontext = u:object_r:rootfs:s0 tclass = file permissive = 0 07-13 15:26:15.431:W / ls(5674):type = 1400 audit(0.0:302 ):avc:拒绝{getattr} for path =“/ ueventd.ranchu.rc”dev =“rootfs”ino = 4002 scontext = u:r:shell:s0 tcontext = u:object_r:rootfs:s0 tclass = file permissive = 0 01-01 00:00:00.000:E /( - 1):LogCat连接错误01-01 00:00:00.000:E /( - 1):设备断开:1 01-01 00:00:00.000:E /( - 1):设备已断开连接

0 个答案:

没有答案