Need to print a string outside
I need to print the"string bb" outside jComboBox1ActionPerformed method, but its throwing an error as"<identifier> expected". My code is
[code]publicclass Mainextends javax.swing.JFrame
{
/** Creates new form Main */
public Main()
{
initComponents();
}
private void initComponents()
{
[lines of code]
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt)
{
String b=null;
Object a=jComboBox1.getSelectedItem();
b=(String)a;
String bb=b.substring(0,1);
System.out.println("bb"+bb);//value of "bb" is printing here
}
System.out.println("bb"+bb);//I need to print here, but I am unable to print, the error shown is "<identifier> expected"
[lines of code]
}[/code]
[978 byte] By [
Simmya] at [2007-11-26 12:47:32]

# 1
First, this isn't really a question about the application server nor performance and tuning. In the future, I think you're more likely to get a response to a question like this if you post in the "New to Java" or "Java Developers" forum.
There are a couple of things wrong with this code. First, the last print statement is completely outside the method body, which is why you're getting a compiler error. I'm not sure what you mean by printing "outside the method" -- all code is executed within some method.
Also, I'm not sure what you're trying to accomplish by defining one method within another. Maybe in the code you've left out there is an anonymous class definition? That would make sense. But the definition of the anonymous class would need to end differently than you have (it would end with a ; and depending on how the beginning of the definition is set up, closing parentheses).
If you get the anonymous class definition correct, then the last problem will be that the variable bb will be out of scope to the outside method: it is declared inside the action performed method, and so that's the only method that knows about it. You will need to declare it in the outer method if you need to print it in the outer method.
sdoa at 2007-7-7 16:29:26 >
