vian marles February 2016

error in insertdata database

please help me for my problem now, In my activities there are two errors , the first in insertdata

@Override
        public void onClick(View arg0) {
            db.open();
            db.insertData(editNama.getText().toString()), cekPria.isChecked(), cekWanita.isChecked(),
            editTanggal.getText().toString();
            db.close();

            Toast.makeText(getBaseContext(),"Data telah disimpan", Toast.LENGTH_SHORT).show();

            editNama.setText("");
            cekPria.setChecked(false);
            cekWanita.setChecked(false);
            editTanggal.setText("");

        }
    });

and a second error in the "variable 'kelamin' might not have been initialized". I give the sign // place the error

public void tampilkanData(){
    db.open();
    Cursor c =db.getAllData();

    ArrayList<String> larik = new ArrayList<String>();

    if (c.moveToFirst()){
        do {
            int idArtis = c.getInt(0);
            String namaArtis = c.getString(1);
            int genderPria = c.getInt(2);
            int genderWanita = c.getInt(3);
            String tgLahir = c.getString(4);

            String kelamin;
            if (genderPria == 1){
                kelamin = "Pria";
            }else if (genderWanita == 1){
                kelamin = "Wanita";
            }else{
                Toast.makeText(getApplicationContext(), "Isi Salah Satu", Toast.LENGTH_SHORT).show();
            }
            //larik.add(Integer.toString(idArtis) + ": " + namaArtis + " (" + kelamin + ") -" + tgLahir);
        }while (c.moveToNext());
    }
    db.close();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, larik);
    listViewData.setAdapter(adapter);
}

this is a code insertData()

public long insertData(String nama, boolean gender, String tanggal){
    try {
        ContentValues dataBaru = new ContentV        

Answers


Rohit5k2 February 2016

Error 1:

This statement is wrong. Should end with ;. Also, looks like misplaced brackets ).

db.insertData(editNama.getText().toString()), cekPria.isChecked(), cekWanita.isChecked(),

Wild guess: This should be

db.insertData(editNama.getText().toString(), cekPria.isChecked(), cekWanita.isChecked());

If you post the code of insertData, we can help your better.

Error 2

Change

String kelamin;

with

String kelamin = null; or String kelamin = ""; as per your needs

Post Status

Asked in February 2016
Viewed 1,193 times
Voted 8
Answered 1 times

Search




Leave an answer