开发者

Trying to add info to database

So this is my first app and first database. I think I have finally created the DBAdapter correctly, and now I am trying to implement that into my main activity.

I have a save button listed under an onClick

public void onClick(View src) {

    switch(src.getId()){

    ...other buttons here...

    case R.id.buttonSave:
        db.open();
        long id;
        id = db.insertFinalscore("20110612", "91", "18");
        db.close();

        break;
    }
}

As I'm sure you can not see, I am tryin开发者_如何学Cg to insert that data into the table. I have created an instance of DBAdapter inside my onClick:

public void onClick(View src) {

    //***DATABASE INFO***//
    DBAdapter db = new DBAdapter(this);

Is anyone able to tell me what I am missing? I am getting the following warning:

        case R.id.buttonSave:
        db.open();
        long id;   <--- The local variable id is never read
        id = db.insertFinalscore("20110612", "91", "18");
        db.close();


You are getting a warning, not an error. Basically the warning is saying that the variable id is never actually used. While you do set its value, you never read that value making the variable worthless. Your program will run just fine as is, but you might as well remove the variable id.

Your program should now look like this:

public void onClick(View src) {

    switch(src.getId()){

    ...other buttons here...

    case R.id.buttonSave:
        db.open();
        db.insertFinalscore("20110612", "91", "18");
        db.close();

        break;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜