什么会导致错误"无法从光标读取"在Logcat?

时间:2015-07-31 10:52:50

标签: android cursor

这是包含我为我的应用程序创建的数据库函数的java类。

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Bundle bundle = getArguments();

    if (bundle != null && bundle.containsKey("personal")) {
        ArrayList<String> userId = bundle.getStringArrayList("personal");
    }
    else{
        Toast.makeText(getActivity(),"Bundle is null",Toast.LENGTH_SHORT).show();
    }
}

我注意到查询语句是造成问题的原因,但我不知道getInformation方法中上面的查询语句的具体问题。

 public class DatabaseOperations extends SQLiteOpenHelper{
      public static final int database_version = 2;
      private static final String TEXT_TYPE = " text";
      private static final String COMMA_SEP = ", ";
      private static final String CREATE_QUERY = "create table "
                + TableData.TableInfo.TABLE_NAME + " ("
                /*+ TableData.TableInfo.KEY_ID + " integer primary key autoincrement, "*/
                + TableData.TableInfo.USER_EMAIL + TEXT_TYPE + COMMA_SEP
                + TableData.TableInfo.USER_NAME + TEXT_TYPE + COMMA_SEP
                + TableData.TableInfo.USER_PASSWORD + TEXT_TYPE + COMMA_SEP
                + "); ";

 public DatabaseOperations(Context context) {
    super(context, TableData.TableInfo.DATABASE_NAME, null, database_version);
    Log.d("Database Operations", "Database created");
 }

 @Override
 public void onCreate(SQLiteDatabase sdb) {
    Log.d("database Operations","Table created");
 }

 @Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    onCreate(db);
 }
 public void putInformation(DatabaseOperations dop, String name,String password,String email)
 {
    SQLiteDatabase SQ = dop.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(TableData.TableInfo.USER_EMAIL, email);
    cv.put(TableData.TableInfo.USER_NAME,name);
    cv.put(TableData.TableInfo.USER_PASSWORD, password);
    //cv.put(TableData.TableInfo.USER_CON,con_password);
    SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
    Log.d("database Operations", "One raw inserted");
 }
 public Cursor getInformation(DatabaseOperations dop) //Method used to retrieve data from database
 {

    SQLiteDatabase SQ = dop.getReadableDatabase();
    String[] columns = {TableData.TableInfo.USER_EMAIL,TableData.TableInfo.USER_NAME,TableData.TableInfo.USER_PASSWORD};
    Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME,columns,null,null,null,null,null);
    return CR;
 }
}

此函数调用包含游标对象的其他函数。我想了解错误出现的可能原因是什么,以及我可以做些什么来解决它。谢谢。

0 个答案:

没有答案