0
Can we Use variables declared in outer block
i need to access variables declared outside the block ,so any ideas.i tried many methods but all seem to fail so my code contains to get a text entered by the user like –------------------------------------ JTextBox text=new JTextBox(); String name; {//action listener part on clicking a button { name=text.getText(); System.out.println(name);//error occurs } } --------------------------------------- so any ideas thanks in advance
4 ответов
+ 2
Post the error message
+ 2
Can't see the error clearly, but try declaring the variables globally.
0
can't access elements of outer block
0
Exception in thread"awt-eventqueue-0" java.lang.error
cannot refer to a non final name inside an inner class defined in a different method
tried posting it globally but didn't help