lawang code

lawang Code


Tanyakan kode disini

Solusi untuk pemasalahan di Android studio.

ditanyakan oleh Kris 3 tahun yang lalu

Solusi untuk permasalahan ini gimana ya gan ?

Caused by: android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1 at android.database.AbstractCursor.checkPosition(AbstractCursor.java:432) at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:147) at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:61) at com.example.irenius.proyeklala.Home.RefreshList(Home.java:40) at com.example.irenius.proyeklala.Home.onCreate(Home.java:28) at android.app.Activity.performCreate(Activity.java:5357) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2434) at android.app.ActivityThread.access$800(ActivityThread.java:154) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)

Ini source code nya : public class Home extends AppCompatActivity {

JualBarangDBHelper dbcenter;
protected Cursor cursor;
String[] daftar;
ListView list;
public static Home hom;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    dbcenter = new JualBarangDBHelper(this);
    hom = this;
    RefreshList();
}


public void RefreshList() {

    SQLiteDatabase db = dbcenter.getReadableDatabase();
    cursor = db.rawQuery("SELECT * FROM jualbarang", null);
    daftar = new String[cursor.getCount()];
    cursor.moveToFirst();
    for (int cc = 0; cc < cursor.getCount(); cc++) {
        cursor.moveToPosition(cc);
        daftar[cc] = cursor.getString(0).toString();
    }
    list = (ListView) findViewById(R.id.listView1);
    list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, daftar));
    list.setSelected(true);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {


        public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
            final String selection = daftar[arg2]; //.getItemAtPosition(arg2).toString();

            Intent i = new Intent(getApplicationContext(), Detail.class);
            i.putExtra("no", selection);
            startActivity(i);
        }
    });
    ((ArrayAdapter) list.getAdapter()).notifyDataSetInvalidated();
}

}

Mohon solusi gan ? terima kasih.

Anda harus login terlebih dahulu untuk memberikan komentar

Recent Tag

X 6
X 48
X 14
X 10
X 1
X 5
X 4
X 18
X 10

Bantuan

Help

Feedback

Help