I'm a beginner and am learning how to use methods. The IDE I'm using is NetBeans.
Although I've spent a lot of time looking through the short program below, I can't figure out what's causing the errors in lines 13 and 14.
Could you please give me some suggestions as to how I can figure out what is causing these errors? I believe that the error is something very simple and really what I want to learn is how to go about finding the cause of those errors, rather than a solution for this particular program.
The error message from Netbeans is as follows;
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - not a statement
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Don't worry on not seeing it. It took me some time to see it as well.
Eclipse will actually put a little red squiggly line underneath the pieces of code that cause compiler errors. I'm pretty sure Netbeans can do the same.
Here are the error messages I see when using the javac compiler on the command line:
While the text of the messages isn't much more informative than what you already saw, it's worth noting that they do provide a little ^ character which points to the approximate location in the line where the error occurred. Or at least, where the compiler thinks the error occurred. This isn't entirely reliable, since when the compiler doesn't understand what you're doing, its guess about what you are trying to do may be badly inaccurate. Still, the ^ can provide useful clues about what part of the line is the problem. In this case, the error at least points to the "int i++" part of the statement.
I don't know if NetBeans preserves the ^ part of the message that the compiler is giving you. If not, that's an extra reason to switch to another means for compiling and running your programs. Even using javac from the command line may give you more information. But maybe if you look closely, NetBeans might actually have some sort of visual indicator about which part of the line is the problem, the way eclipse and IntelliJ do.
Joined: Oct 13, 2005
I think you might be better using the command-line and a decent text editor, leaving IDEs until you are more experienced.
Also, the sum function is not generalized. It will not work when k<j and for -ve inputs (j=-1 and k=-10). >
Joined: Oct 13, 2005
Also note that javac is giving three error messages for the price of one. If that happens, it is always worth looking at what appears to be the first error (marked by the caret symbol ^), correcting that and re-compiling.
Thanks everyone. Unfortunately my IDE doesn't show the " ^" symbol. I've been using an IDE for a little while now and find it easier than using a text editor and command line, so will probably stick with it at least for the moment.
Joined: Mar 05, 2008
OK, but this suggests that NetBeans is a relatively crappy IDE if it loses the location info associated with those error messages. I think Eclipse or IntelliJ may serve you better in the long run. I've never used NetBeans much, but I can recommend either Eclipse or IntelliJ (I favor IntelliJ).