0

您好,我正在尝试调用服务的 android 方法,因为 public void onclick 并且我有一个错误,它告诉我需要插入“AssignemetOperator Expression”来完成表达式,但我看不出错误在哪里。我把代码放在这里错误是在布尔 ret=bindService(......... 它在 public void onClick idcamarero 的内部是如何创建一个全局变量谢谢

View.OnClickListener buttonhandler=new View.OnClickListener() {

    public void onClick(View v) {
        EditText id_camarero = (EditText) findViewById(R.id.id_camarero);
        String numero = id_camarero.getText().toString();
        idcamarero=Integer.parseInt(numero);
        //Register the actions we want to receive via broadcast
        //MyService.LocalBinder.
     boolean ret= bindService(new Intent(MainActivity.this, MyService.class), androidServiceConnection, BIND_AUTO_CREATE);          
         IntentFilter filter = new IntentFilter(MyService.DATA_RECEIVED_INTENT);
         registerReceiver(androidListener, filter);
     if((numero.trim().equals(""))||(existe==false)){
         AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

                // set title
                alertDialogBuilder.setTitle("Fallo de id");

                // set dialog message
                alertDialogBuilder
                    //.setMessage("Click salir para finalizarprograma")
                    .setCancelable(false)
                    .setPositiveButton("Salir",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, close
                            // current activity
                            MainActivity.this.finish();
                        }
                      })
                    .setNegativeButton("Reintentar",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, just close
                            // the dialog box and do nothing
                            dialog.cancel();
                        }
                    });

                    // create alert dialog
                    AlertDialog alertDialog = alertDialogBuilder.create();

                    // show it
                    alertDialog.show();
                }

     else{
    // Intent intent= new Intent(GestorRestauranteActivity.this,MenuMesas.class);
    // intent.putExtra("id", numero);//enviamos el id de camarero a la actividad que invocamos
    // startActivity(intent);
     finish();
     }
    }

};
4

1 回答 1

0

代码的第 5 行:

idcamarero=Integer.parseInt(numero);

不会解析,因为您尚未声明变量的类型idcamarero。您需要在该行前面加上前缀int或将其完全删除(看起来您不需要这个)。

于 2012-07-16T11:59:21.260 回答