【发布时间】:2012-09-27 01:35:39
【问题描述】:
代码:
final String nome = nm.getText().toString();
final String telefone = tlf.getText().toString();
if(nome.length() != 0 && telefone.length() != 0){
if(mIndex.equals("")) {
ContentValues valor = new ContentValues();
valor.put("nome", nome);
valor.put("telefone", telefone);
db.insert("contatos", null, valor);
ShowMessage("Sucesso","O Contato " + nome + " foi salvo com sucesso");
}
else {
String[] whereArgs = {"nome", "telefone"};
ContentValues dataToInsert = new ContentValues();
dataToInsert.put("nome", nome);
dataToInsert.put("telefone", telefone);
db.update("contatos", dataToInsert, "nome='"+nomeant+"' and telefone='"+foneant+"' ", whereArgs);
ShowMessage("Sucesso","O Contato " + nome + " foi editado com sucesso");
}
}
因此,mIndex 是上一个活动中联系人的索引(我选择并单击项目/联系人,然后将索引传递给新活动)因此,如果 EditTexts 已经为空白,它将添加一个新联系人,如果 EditTexts 有一个值并被更改,它将改变 Clicked Contacts 值(姓名/电话)。但是当我点击 SAVE 按钮时,我的应用程序崩溃了,但错误出现在 db.update 行中。
db.update("contatos", dataToInsert, "nome='"+nomeant+"' and telefone='"+foneant+"' ", whereArgs); 所以我猜 whereClause 或 whereArgs 是错误的,但因为我在 Android 编程方面没有很高的智能。
【问题讨论】:
-
这里,我的另一个问题的 [LINK[(stackoverflow.com/questions/12589582/…),它有 LogCat 错误和我的 main.Java 的代码,现在我没有打开“VerificaDados();”在我的 onCreate 中,所以数据库没有显示错误。
-
试试 Mukesh Soni 建议的答案