2012-12-11 2 views
1

내 데이터베이스에서 3 개의 열을 업데이트하려고합니다. 하지만 난 항상 내 logcat에 javanullexception지고 있어요.android에서 테이블 업데이트

다음은 업데이트 방법입니다.

public void updateDetails(View v) 
{ 
    UpdateBtn = (ImageButton)findViewById(R.id.updateBtn); 
    HeightIn = (EditText)findViewById(R.id.heightIn); 
    HeightFt = (EditText)findViewById(R.id.heightFt); 
    Weight = (EditText)findViewById(R.id.weight); 

    UpdateBtn.setImageResource(com.example.gym.trainer.R.drawable.updatebtn2); 
    UpdateBtn.setClickable(false); 
    HeightIn.setEnabled(false); 
    HeightFt.setEnabled(false); 
    Weight.setEnabled(false); 

    //Toast.makeText(getBaseContext(), Integer.parseInt(id) + ", " + String.valueOf(HeightFt.getText()) + ", " + String.valueOf(HeightIn.getText()) + ", " + String.valueOf(Weight.getText()), Toast.LENGTH_LONG).show(); 

    DBAdapter db = new DBAdapter(this); 

    boolean success = db.updateHeightWeight(Integer.parseInt(id), String.valueOf(HeightFt.getText()), String.valueOf(HeightIn.getText()), String.valueOf(Weight.getText())); 

    if(success == true) 
     Toast.makeText(getBaseContext(), "Update Successful", Toast.LENGTH_SHORT).show(); 
    else 
     Toast.makeText(getBaseContext(), "Update Failed", Toast.LENGTH_SHORT).show(); 

} 

값은 주석 처리 된 토스트를 사용하여 표시 할 수 있으므로 값이 있는지 확인할 수 있습니다.

내 DBAdapter 클래스에서

:

public boolean updateHeightWeight(int rowId, String heightft, String heightin, String weight) 
{ 
    ContentValues args2 = new ContentValues(); 
    args2.put(KEY_HEIGHTFT, heightft); 
    args2.put(KEY_HEIGHTIN, heightin); 
    args2.put(KEY_WEIGHT, weight); 
    return db.update(DATABASE_TABLE, args2, 
         KEY_ROWID + "=" + rowId, null) > 0;// this is where the exception occurs 
} 

여기 내 DBAdapter 클래스의 변수이다. 내 테이블의

public static final String KEY_ROWID = "_id"; 
public static final String KEY_HEIGHTFT = "heightft"; 
public static final String KEY_HEIGHTIN = "heightin"; 
public static final String KEY_WEIGHT = "weight"; 

구조 : 내 문제를 해결하는 방법에 대한

private static final String DATABASE_CREATE = 
    "create table if not exists profiles (_id integer primary key autoincrement, " 
    + "firstname VARCHAR not null, age VARCHAR not null, " 
    + "heightft VARCHAR not null, heightin VARCHAR not null, weight VARCHAR not null, duration VARCHAR not null, bmi VARCHAR not null);"; 

어떤 아이디어? 감사!

+0

어떤 줄이 NullException을 제공합니까? –

+0

return db.update (DATABASE_TABLE, args2, KEY_ROWID + "="+ rowId, null)> 0; 이 하나의 선생 – ljpv14

답변

1

데이터베이스를 사용하기 전에 데이터베이스를 열지 않았습니까? 이런 종류의 일은 매우 일반적입니다.

DBAdapter db = new DBAdapter(this); 
    db.open(); <----------- 
    boolean success = db.updateHeightWeight(Integer.parseInt(id), String.valueOf(HeightFt.getText()), String.valueOf(HeightIn.getText()), String.valueOf(Weight.getText())); 
+0

나는 그 실수를 진심으로 유감스럽게 생각한다. 다음에는 그 간단한 오류를 살펴볼 것입니다. 감사! – ljpv14