2011-07-11 2 views
1

Salut je travaille avec android et j'essaye de mettre un "si" déclaration autour de cette classe mais j'obtiens l'erreur "erreur de syntaxe sur le jeton" si ", AnnotationNo invalide " Toute aide?Erreur de syntaxe sur le jeton "si", invalide AnnotationName

private String str = "0"; 
if(str == 0){ 
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    { 

     //Handle the back button 
     if(keyCode == KeyEvent.KEYCODE_BACK) 
     { 
      //Ask the user if they want to quit 
      new AlertDialog.Builder(this) 
      .setIcon(android.R.drawable.ic_dialog_alert) 
      .setTitle("Coupon") 
      .setMessage("Do you want a coupon texted to you?") 
      .setPositiveButton("YES!", new DialogInterface.OnClickListener() 
      { 
       @Override 
       public void onClick(DialogInterface dialog, int which) 
       { 
        //Stop the activity 
        Toast.makeText(buttonOne.this, "Great! You'll get one in just a couple of minutes.", Toast.LENGTH_LONG).show(); 
        finish(); 
       } 
      }) 
      .setNegativeButton("Not now", new DialogInterface.OnClickListener() 
      { 
       @Override 
       public void onClick(DialogInterface dialog, int which) 
       { 
        //Stop the activity 
        finish(); 
       } 
      }) 
      .show();   
      return true; 
     } 
     else 
     { 
      return super.onKeyDown(keyCode, event); 
     } 

    } 
} 
else 
{} 

Répondre

13

Vous ne pouvez pas mettre des structures de contrôle (comme if états) en dehors d'une fonction.

1

vous devez utiliser equals méthode String:

if (str.equals("0")){ 
    ... 
} 
Questions connexes