java.lang.IllegalStateException: 无法从 CursorWindow 读取第 0 行第 2 列

java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow

我在从 SQLLite 数据库中检索数据时遇到异常。

  java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it

在线String username= result.getString(1);

主要活动

mSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SQLiteDatabase myDatabase=openOrCreateDatabase("Login",MODE_PRIVATE,null);
                myDatabase.execSQL("CREATE TABLE IF NOT EXISTS Login(Username VARCHAR,Password VARCHAR);");
                myDatabase.execSQL("INSERT INTO Login VALUES('"+mUserName.getText()+"','"+mPassword.getText()+"');");

            }
        });

第二个活动

  SQLiteDatabase myDatabase=openOrCreateDatabase("Login",MODE_PRIVATE,null);

                Cursor result=myDatabase.rawQuery("Select * from Login",null);
             result.moveToFirst();
                String username= result.getString(1);
                String password=result.getString(2);

我哪里错了?

这应该是

 String username= result.getString(0);
 String password=result.getString(1);

游标索引从零开始

完整代码

SQLiteDatabase myDatabase=openOrCreateDatabase("Login",MODE_PRIVATE,null);
Cursor result=myDatabase.rawQuery("Select * from Login",null);
if (result.moveToFirst()) {      
   String username= result.getString(0);
   String password=result.getString(1);                
}