我正在显示一个对话框。当按下后退键时,我正在编写代码并使用后退键默认功能,但每次出现以下错误时,这都是我的代码:
public void myfunc {
new AlertDialog.Builder(TaxiPlexer.this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Enable GPS").setMessage(
"Please Enable GPS in device settings to use Taxi application").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do something
} // onClick
}).show();
@Override //error: Syntax error on token(s), misplaced construct(s)
public void onBackPressed() { //error: Syntax error on token "void", @ expected
GPSdialog = false;
super.onBackPressed();
} }
答案 0 :(得分:0)
这是正确的语法。您重写方法。所以你必须把方法放在一个类而不是另一个方法中。
public void myfunc {
new AlertDialog.Builder(TaxiPlexer.this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Enable GPS").setMessage(
"Please Enable GPS in device settings to use Taxi application").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//do something
} // onClick
}).show();
}
@Override //error: Syntax error on token(s), misplaced construct(s)
public void onBackPressed() { //error: Syntax error on token "void", @ expected
GPSdialog = false;
super.onBackPressed();
}