Java Reference
In-Depth Information
3.
On the “Save and Launch” window, click the OK button. RAD will display a Java Virtual
Machine Launcher window with a Fatal exception message and in the Console view one of
the most common Java application error messages will be displayed:
Exception in thread "main" java.lang.NoSuchMethodError: myFirstPackage/
EmployeeApp.main([Ljava/lang/String;)V
The key portions of this message are the text “NoSuchMethodError” and then the identification of the main
method—“myFirstPackage/EmployeeApp.main.” Notice that the error message doesn't tell you exactly what the
problem is (i.e., the Main method doesn't begin with a lowercase m), only that there is no main method. Really, what
the message means is that there is no main method coded exactly as it is needs to be . The main method header has
to be coded exactly as specified earlier. Any deviation will result in the above error. When you get this error, you will
have to figure out which picky Java syntax requirement was violated in the main method and correct it.
4.
Close the Java Virtual Machine Launcher window by clicking the OK button.
5.
Put the lower case m back in the header by clicking Edit then Undo in the menu bar.
Notice that RAD will undo the change even though the source code was saved.
6.
Save the source code, and run the program to verify that code was fixed correctly.
Now, let's break something else!
7.
Select the entire main method.
8.
Cut and paste the method after the EmployeeApp class' ending brace.
Notice that there is now a red squiggly line under the class and main 'method's closing braces. Like a word
processor, this is another way RAD indicates that there is an error. Again, we'll ignore 'RAD's warnings and run the
application.
9.
Run the application by selecting the EmployeeApp run configuration.
10.
On the Save and Launch window, click the OK button (to save the changes).
RAD tries to warn us about errors by displaying the Errors in Workspace window. (Please also notice that RAD
calls “running an application” a “launch.” Launches will come up later in the topic.)
11.
Click the Proceed button on the Errors in Workspace window to run the application.
The following error message will be displayed in the Console:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "}" to complete ClassBody
at myFirstPackage.EmployeeApp.main(EmployeeApp.java:16)
The first line of the error message simply means there was a fundamental Java language syntax error
(i.e., compilation problem). The second line tries to pinpoint the error and offer a solution (i.e., there is a syntax
error because the class body was never ended with a closing brace.) The red squiggly line under the first closing
brace indicates that RAD thinks that token is incorrect. If you move the cursor over that error icon or the red squiggly
line, RAD will display a message saying that the token } should be deleted. However, the real problem is that the main
method is outside of the class body. Obviously, RAD is not too good at identifying this particular error. The third line
of text explains where the error was found. Notice it contains the package name, class name, and method name where
the error was found, as well as, a hyperlink to the suspected line with the error.
12.
Move the mouse pointer over the third line of the message and click the hyperlink.
 
Search WWH ::




Custom Search