错误 "Unable to start activity ComponentInfo" 不知道如何修复它

Error "Unable to start activity ComponentInfo" cant figure out how to fix it

我有一些字符串,我在第一个 activity 上写入了 Edittext,我试图通过按下按钮将它发送到另一个 activity 上的 Edittext,但它给了我一个错误“java.lang.RuntimeException:无法启动 activity ComponentInfo{com.example.kp_orginizer/com.example.kp_orginizer.calendar}:android.database.CursorIndexOutOfBoundsException:请求索引 0,大小为0

有人可以帮我吗

这是我在第一个 Activity 上的 onCLick 方法:

    public void calendarOR(View v, AdapterView<?> parent, int position, long id) {
        String data = cala.getText().toString();
        Intent intent = new Intent(this, calendar.class);
        intent.putExtra("id",data);
        startActivity(intent);

我的第二种方法:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    userId = extras.getString("id");
}
if (userId !=null) {
    userCursor = db.rawQuery("select * from " + dbelper.TABLE + " where " + dbelper.COLUMN_ID + "=?", new String[]{userId});
    userCursor.moveToFirst();
    date.setText(userCursor.getString(1));
    userCursor.close();
}

它抱怨“date.setText(userCursor.getString(1));”字符串

这是一个错误代码:

    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.kp_orginizer, PID: 7787
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kp_orginizer/com.example.kp_orginizer.calendar}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
 Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:515)
    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:138)
    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:52)
    at com.example.kp_orginizer.calendar.onCreate(calendar.java:94)
    at android.app.Activity.performCreate(Activity.java:7802)
    at android.app.Activity.performCreate(Activity.java:7791)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7356) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 

这是我填充数据库的方式:

    public void save(View view) {

        ContentValues cv = new ContentValues();
        int idishnik = 1;
        cv.put(dbelper.COLUMN_NOTE, note.getText().toString());
        cv.put(dbelper.COLUMN_DATE, cala.getText().toString());
        cv.put(dbelper.ID_TABLITSY, idishnik);

        if (userId > 0) {
            db.update(dbelper.TABLE, cv, dbelper.COLUMN_ID + "=" + userId, null);
        } else {
            db.insert(dbelper.TABLE, null, cv);
        }
        goHome();
    }

您传递的内容似乎是 userId 不是 valid/present 数据库键。如果您只想显示您在 EditText 中传递的内容,而不是使用它从数据库中获取某些内容,您只需这样做

if (userId != null) {
    date.setText(userId);
}