0

我收到以下错误,我在教程中确实(afaik)作为一个人,但我仍然收到错误:“无法从类型对话框中对非静态方法 show() 进行静态引用”在“AlertDialog.节目();” “AlertDialog 无法解析或不是字段”在“AlertDialog.alertDialog = dialogBu​​ilder.create();”

这是我的代码:

public Button paginanoua;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    paginanoua = (Button) findViewById(R.id.paginanoua);

    paginanoua.setOnClickListener(this);

}

public void onClick(View view) {
    ShowDialog();
}

private void ShowDialog() {

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle("Pagina noua..");
    dialogBuilder.setMessage("Sigur doriti o pagina noua?");
    dialogBuilder.setPositiveButton("Da",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {

                    Toast.makeText(getApplicationContext(),
                            "Am inceput o lista noua", Toast.LENGTH_SHORT)
                            .show();
                }

            });
    dialogBuilder.setNegativeButton("Nu",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    Toast.makeText(getApplicationContext(),
                            "Ramanem la lista curenta", Toast.LENGTH_SHORT)
                            .show();
                }
            });
    AlertDialog.alertDialog = dialogBuilder.create();
    AlertDialog.show();
}

我做错了什么 ?

4

2 回答 2

3

您没有为变量声明名称。

改变它:

AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
于 2013-06-08T17:45:58.080 回答
1

尝试这个

代替

   AlertDialog.alertDialog = dialogBuilder.create();
   AlertDialog.show();  

这样

   AlertDialog alertDialog = dialogBuilder.create();
   alertDialog.show();

或正如@blackbelt 所建议的那样

   dialogBuilder.show(); 
于 2013-06-08T17:48:01.273 回答