我試圖顯示一條警告消息。 但是當我點擊特定的按鈕來顯示警告消息時,應用程序不幸停止。如何在Android應用程序中顯示警報消息
我警報消息代碼是在這裏...
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Cursor res = myDB.getAllData();
if (res.getCount() == 0) {
showMessage("Error", "Nothing found");
return;
}
StringBuffer buffer = new StringBuffer();
while (res.moveToNext()) {
buffer.append("EMAIL: " + res.getString(0) + "\n");
buffer.append("full_name : " + res.getString(1) + "\n");
buffer.append("district : " + res.getString(2) + "\n");
buffer.append("phone_num : " + res.getString(3) + "\n");
}
showMessage("Data", buffer.toString());
}
});
}
public void showMessage(String title, String message)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
檢查您是否打開數據庫連接(即檢查myDB是否爲空並且遊標返回非空)。 –
它更好地發送您的logcat了 –