aspose file tools*
The moose likes Beginning Java and the fly likes Trying to figure out Exception Error in code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to figure out Exception Error in code" Watch "Trying to figure out Exception Error in code" New topic
Author

Trying to figure out Exception Error in code

LeeAnne Murphy
Greenhorn

Joined: Aug 15, 2011
Posts: 18





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

Joined: Jul 16, 2011
Posts: 90
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

Joined: Jul 19, 2011
Posts: 175

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...


Please correct my English.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11420
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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!


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
LeeAnne Murphy
Greenhorn

Joined: Aug 15, 2011
Posts: 18

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
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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.
 
jQuery in Action, 2nd edition
 
subject: Trying to figure out Exception Error in code