你好每个人都有问题。我想在Android设备上显示一些数据,但我面临的错误是StringBuffer(无法访问的Statement)这里是我的代码
public void ShowData()
{
btnShow.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor result = database.showAllData();
if (result.getCount() == 0);
{
showMessage("Error","Nothing is here");
return;
}
StringBuffer buffer = new StringBuffer();
while(result.moveToNext())
{
buffer.append("name"+result.getString(0)+"\n");
buffer.append("userName"+result.getString(0)+"\n");
buffer.append("password"+result.getString(0)+"\n\n");
}
showMessage("Data",buffer.toString());
}
}
);
}
public void showMessage (String title, String message)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
答案 0 :(得分:1)
在;
之后移除if (result.getCount() == 0);
。它终止if语句,后面的语句不是有条件的,而是每次都会执行。