mardi 3 janvier 2017

Java variable inside "if" not recognized

I have assignment to create an atm program for my class. I've mostly done everything except this one problem. The variable inside an if statement is not recognized. I want to create somekind of id check, the code for assigning the variable to true is not recognized, the else statement that assign the false value is working fine. Here is the code:

boolean k;
String trf = JOptionPane.showInputDialog("Insert [ID <space> Amount]:");
StringTokenizer tr = new StringTokenizer(trf);
tid = tr.nextToken();
int tam = Integer.parseInt(tr.nextToken());
for(int x=0;x<4;x++){
    if (t[x].account.getId().equals(tid)){
       k = true;
       //transfer code here[...]
       break;
    }
    else{
       k=false;
    }
    if(!k){
       JOptionPane.showMessageDialog(null, "ID not found");
    }
}

I read some other topic like this before an one said to define the variable before the if, but i cant do that in my case because i need to check the value first. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire