Reputation: 2883
I'm trying to update an entire row on my sqlite database on android. But for some reason is throwing an exception.
The method that updates my Database is :
public void updateEvent(long rowId,Evento evento){
int row=(int)rowId;
ContentValues eventValues=createContentValues(evento);
db.update(TABLE,eventValues,KEY_ROWID+"="+row,null);
}
The createContentValues method is this:
private ContentValues createContentValues(Evento evento){
ContentValues val=new ContentValues();
val.put(KEY_ROWID,evento.getIdEvento());
val.put(KEY_SUMMARY,evento.getSummario());
val.put(KEY_DAY,evento.getFecha().getDia());
val.put(KEY_MONTH,evento.getFecha().getMes());
val.put(KEY_YEAR,evento.getFecha().getAnho());
val.put(KEY_STATUS,evento.getStatus());
val.put(KEY_NOTES, evento.getNota());
return val;
}
and the method that calls the update method is :
private void acceptAction(Evento evnt,String note){
DbAdapter dbConn=new DbAdapter(this.getApplicationContext());
evnt.setNota(note);
try{
dbConn.updateEvent(evnt.getIdEvento(), evnt);
}catch(Exception e){
Toast.makeText(this.getApplicationContext(), "Error al Actualizar tu Evento", Toast.LENGTH_SHORT).show();
//Log.e("Error Candelaria", e.getMessage());
}
}
The Log Entry line is commented because the Exception object doesn't contains any information, i can't do a printStackTrace()
because println throws a NullPointerException.
UPDATE: Logcat:
04-19 13:53:15.910: E/AndroidRuntime(4934): java.lang.NullPointerException
04-19 13:53:15.910: E/AndroidRuntime(4934): at com.siitne.candelaria.data.DbAdapter.updateEvent(DbAdapter.java:48)
04-19 13:53:15.910: E/AndroidRuntime(4934): at com.siitne.candelaria.ImportantList.acceptAction(ImportantList.java:130)
04-19 13:53:15.910: E/AndroidRuntime(4934): at com.siitne.candelaria.ImportantList.access$3(ImportantList.java:126)
04-19 13:53:15.910: E/AndroidRuntime(4934): at com.siitne.candelaria.ImportantList$1$1.onClick(ImportantList.java:113)
Upvotes: 0
Views: 648
Reputation: 66637
Assuming KEY_ROWID is integer you don't need single quote.
db.update(TABLE,eventValues,KEY_ROWID+"="+row+"",null);
IF not integer then
db.update(TABLE,eventValues,KEY_ROWID+"= '"+row+"'",null);
You don't need to print stacktrace. There is a view called Logcat. That will show complete error stacktrace.
EDIT: It is NullpointerException, not sqlexception. You need to make sure db is not null as well evento also.
Upvotes: 2
Reputation: 22306
KEY_ROWID+"='"+row
you are missing the enclosing '
should read
KEY_ROWID+"='"+row + "'"
Upvotes: 1