• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Trying to figure out Exception Error in code

 
Greenhorn
Posts: 18
Netbeans IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 177
Hibernate Python Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Firefox Browser Windows Vista
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28298
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79716
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic