parse.com 用户 android 的错误消息
parse.com error message for user android
如果查询未找到任何结果,我尝试为我的用户添加一条错误消息。我已经尝试过这段代码,但我现在不知道错误意味着它给我的建设。我对编程很陌生
提前致谢
public void createRechnung(View v) {
if (mBetragInput.getText().length() > 0) {
mName = mNameInput.getSelectedItem().toString();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Grillen");
query.whereEqualTo("name", mName);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException eg) {
if (eg == null && objects.size() > 0) {
mBetrag = mBetragInput.getText().toString();
ParseObject Grillen = objects.get(0);
Grillen.put("Betrag", mBetrag);
Grillen.put("Rechnung", true);
Grillen.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
//success, saved!
Log.d("MyApp", "Successfully saved!");
}
}
});
}else {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Danke");
alertDialog.setMessage("Rechnung wurde erstellt.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mBetragInput.setText("€");
mNameInput.setSelection(0);
}
});
alertDialog.show();
}
}
});
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Danke");
alertDialog.setMessage("Rechnung wurde erstellt.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mBetragInput.setText("€");
mNameInput.setSelection(0);
}
});
alertDialog.show();
}
else {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Achtung");
alertDialog.setMessage("Bitte gib einen Betrag ein!");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}
错误很简单。您需要上下文而不是 FindCallback。尝试获取上下文(activity 上下文而不是应用程序上下文),例如 getActivity(当然如果可能的话)。
new AlertDialog.Builder(this)
上述方法永远不会为您提供上下文,而是为您提供 FindCallback。尝试使用一种方法,而不是为您提供 activity 上下文。示例:
new AlertDialog.Builder(WhateverActivity.this)
类似:
Why does AlertDialog.Builder(Context context) only accepts Activity as a parameter?
改变
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
至
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
将 MainActivity 更改为您 activity 的名称,问题是警告对话框的上下文错误。
如果查询未找到任何结果,我尝试为我的用户添加一条错误消息。我已经尝试过这段代码,但我现在不知道错误意味着它给我的建设。我对编程很陌生
提前致谢
public void createRechnung(View v) {
if (mBetragInput.getText().length() > 0) {
mName = mNameInput.getSelectedItem().toString();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Grillen");
query.whereEqualTo("name", mName);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objects, ParseException eg) {
if (eg == null && objects.size() > 0) {
mBetrag = mBetragInput.getText().toString();
ParseObject Grillen = objects.get(0);
Grillen.put("Betrag", mBetrag);
Grillen.put("Rechnung", true);
Grillen.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
//success, saved!
Log.d("MyApp", "Successfully saved!");
}
}
});
}else {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Danke");
alertDialog.setMessage("Rechnung wurde erstellt.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mBetragInput.setText("€");
mNameInput.setSelection(0);
}
});
alertDialog.show();
}
}
});
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Danke");
alertDialog.setMessage("Rechnung wurde erstellt.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mBetragInput.setText("€");
mNameInput.setSelection(0);
}
});
alertDialog.show();
}
else {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Achtung");
alertDialog.setMessage("Bitte gib einen Betrag ein!");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}
错误很简单。您需要上下文而不是 FindCallback。尝试获取上下文(activity 上下文而不是应用程序上下文),例如 getActivity(当然如果可能的话)。
new AlertDialog.Builder(this)
上述方法永远不会为您提供上下文,而是为您提供 FindCallback。尝试使用一种方法,而不是为您提供 activity 上下文。示例:
new AlertDialog.Builder(WhateverActivity.this)
类似:
Why does AlertDialog.Builder(Context context) only accepts Activity as a parameter?
改变
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
至
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
将 MainActivity 更改为您 activity 的名称,问题是警告对话框的上下文错误。