Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

Fixing Errors

As you compose a program in the NetBeans source editor, errors are flagged with a red alert icon to the left of the editor pane, as shown in Figure 2.2.

FIGURE 2.2

FIGURE 2.2 Spotting errors in the source editor.

The icon appears on the line that triggered the error. You can click this icon to display an error message that explains the compiler error with these details:

  • The name of the Java program
  • The type of error
  • The line where the error was found

Here’s an example of an error message you might see when compiling the Saluton program:

cannot find symbol.
symbol  : variable greting
location: class Saluton

The error is the first line of the message: “cannot find symbol.” These messages often can be confusing to new programmers. When the error message doesn’t make sense to you, don’t spend much time trying to figure it out. Instead, take a look at the line where the error occurred and look for the most obvious causes.

For instance, can you determine what’s wrong with the following statement?

System.out.println(greting);

The error is a typo in the variable name, which should be greeting instead of greting. (Add this typo on purpose in NetBeans to see what happens.)

If you get error messages when creating the Saluton program, double-check that your program matches Listing 2.2 and correct any differences you find. Make sure that everything is capitalized correctly and all punctuation marks such as {, }, and ; are included.

Often, a close look at the line identified by the error message is enough to reveal the error (or errors) that need to be fixed.

  • + Share This
  • 🔖 Save To Your Account