Home > Back-end >  Error "Unable to start activity ComponentInfo" cant figure out how to fix it
Error "Unable to start activity ComponentInfo" cant figure out how to fix it

Time:12-25

I have some string that i write into the Edittext on my first activity and im trying to send it to the Edittext on the other activity by pressing Button, but it gives me an Error "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"

Could somebody please help me

Here is my onCLick method on the first Activity:

    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);

My second method:

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();
}

It is complaining about "date.setText(userCursor.getString(1));" string

Here is an Error code:

    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) 

This is how i fill my database:

    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();
    }

CodePudding user response:

It would appear what you are passing as userId is not a valid/present database key. If you just want to show what you passed in the EditText instead of using it to get something from the database you would just do

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