how can i acess a variable outside of an if statement in java
        Posted  
        
            by 
                themanepalli
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by themanepalli
        
        
        
        Published on 2010-12-28T02:46:05Z
        Indexed on 
            2010/12/28
            2:53 UTC
        
        
        Read the original article
        Hit count: 291
        
i have defined a variable inside an if statement and I am trying to access it outside of that if statement now. now the error is saying that it cannot find the symbol which is because its being defined as an intance variable, is there a way i can change it so i can access it outside the variable? heres the code
if((e.getSource()==userOrder2)&& (orderType==1))
{ String buyO= userOrder2.getText(); int buyOrder= Integer.parseInt(buyO); //variable im trying to access }
  // trying to use buyOrder in a different if statement
  if(orderType==1 && (stockPrice <= buyOrder))
  {
 orderResult.setText("The Stock" + (stockName2.getText()) + "was bought at" + stockPrice);
  }
© Stack Overflow or respective owner