Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trying to figure out Exception Error in code

 
LeeAnne Murphy
Greenhorn
Posts: 18
Firefox Browser Netbeans IDE Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




Here is the error :

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
at jp2.wk2mortcalc.JP2Wk2mortcalc.main(JP2Wk2mortcalc.java:46)

 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is telling you exactly where to look - line 46.

private double principal;

I will give you a clue, you are declaring this in main, ie not a class.

 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags. This is impossible to read!
I suggest you look on basic Java tutorials first too.
You try to learn running before you are able to walk here I guess...
 
fred rosenberger
lowercase baba
Bartender
Posts: 12124
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put code tags around your java, making it much easier to read. Please use them in the future - it's just like making something bold or italicized - highlight what you want, then click the button labled "code" and you'll see them pop in.


Now that the code is formatted in such a way that I can read it...you'll notice several strange things. Your main() method starts on line 42, but before it ends you start a new method...

basically, you seem to have a lot of formatting errors. I don't know how you got this far without finding the problem. You should NEVER write more than 2-3 lines of code before you re-compile. writing 300+ before you do your first compile is guaranteed to cause you nothing but grief and pain.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also I see that it is a RuntimeException. Normally this would be a compile time exception. I'm going to assume that you even though your ide complained that there where errors in your code you ran it anyway. Don't do that. Always fix compile-time errors before running.

Edit: And welcome to the JavaRanch!
 
LeeAnne Murphy
Greenhorn
Posts: 18
Firefox Browser Netbeans IDE Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I moved those 3 lines but now I get the exception error on line 53.

Here is the line. I am not understanding the exception error and what it means or what I need to make it go away.

public class MortCalc extends JFrame implements ActionListener

Same from the code I posted earlier.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's like Fred said: you've got too much code. Hacking out random bits isn't going to get you anywhere, unless you get lucky. So what I would recommend is this:

Start over. No, I don't mean throw out what you have. Just start over with a new class and build it up a bit at a time. The bits are going to come from what you already have, just extract small bits and put them into the new code carefully. And like Fred said, keep compiling as you rebuild your code.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a bit surprised Fred didn't say, as he often does, to start with code like thisNow you can see that the class is compiling, and then you can add some real code. As Campbell Ritchie often says, write 5 lines, compile and run, then add another 5 lines. If you do it like that you can see the thing working and find errors so much more easily.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic