This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello All, When I try and complie the below code I get the following errors:
Can someone please help me figure out how to fix my errors? Thanks Stacey [ edited to preserve formatting of pasted compiler errors using the [code] and [/code] UBB tags -ds ] [ December 14, 2003: Message edited by: Dirk Schreckmann ]
Well first of all, unless I'm mistaken: 1) getText(textfield_1) should be changed to textfield_1.getText() -- unless you have the original function defined somewhere .. probably not though. 2) As for the action listener, it looks like cmdQuote is outside the scope of where it is referenced. If you were trying to make that QuoteLayout a nested class, then you would be able to reference cmdQuote, but not as it is. You can change Quote to implement some Quote.getQuoteLayout() or something like that so you can retrieve it, or you can correct your file to make QuoteLayout a nested class of Quote. Hope that helps.
When interpretting compiler errors, it's often the first error message displayed that refers to the real culprit. In your case, the frist error message is complaining about in illegal start of an expression where your code reads public String panel inside of a method. Note that the public keyword is used to modify the accessibility of a class member, or of an instance member, or of a constructor. If a variable is declared inside of a method, then that variable only exists inside of that method and is only accessible inside of that method. So, it isn't necessary, nor does it make sense, to modify the accessibility of a variable inside of a method. In other words, remove the keyword public from that line. After fixing that compiler error, you'll be greeted by another - <identifier> expected on that last line of code which reads cmdQuote.addActionListener(alarmListener); Java doesn't allow you to just call methods from code that is outside of a code block. (Here I'm considering code that defines class members and instance members to be outside of a code block.) You could take this line of code and put it in the constructor of QuoteLayout, but of course then the compiler will complain about not knowing what cmdQuote is. cmdQuote is something that you've defined in a different class. Perhaps you actually wanted to add the action listener to cmdQuote from the other class. How's it going?