5 Replies - 565 Views - Last Post: 24 September 2013 - 03:23 PM Rate Topic: -----

#1 drunkfoo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-September 13

How to troubleshoot "Exception in thread "main" java.lang.

Posted 19 September 2013 - 02:21 PM

I'm writing a prog that takes input of starting balance in an account, the annual interest rate, monthly income, and a withdrawl amount. It should store a monthly interest when user inputs an annual interest rate.

This is the message I get when I run:
What is your account's starting balance? 500
What is your annual interest rate? 1.5
Exception in thread "main" java.lang.NoClassDefFoundError: BankAccount
at Program2.main(Program2.java:42)
Caused by: java.lang.ClassNotFoundException: BankAccount
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more

The first error is at line 42: account = new BankAccount (balance, interestRate);

Can you give me an idea of how to troubleshoot the error "Exception in thread "main" java.lang.NoClassDefFoundError" ?

Is This A Good Question/Topic? 0
  • +

Replies To: How to troubleshoot "Exception in thread "main" java.lang.

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: How to troubleshoot "Exception in thread "main" java.lang.

Posted 19 September 2013 - 02:26 PM

There's little troubleshooting to do. The solution is to place the BankAccount.java source file where the compiler can find it, because the compiler can't find your BankAccount class. Is the source file called BankAccount.java? Is the source code file in the same directory as the Program2.java source file?
Was This Post Helpful? 0
  • +
  • -

#3 drunkfoo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-September 13

Re: How to troubleshoot "Exception in thread "main" java.lang.

Posted 20 September 2013 - 02:44 PM

Yes. Both files are in the same folder. The two classes are "BankAccount.java" and "Program2.java". The Program2 class is the driver class that uses the BankAccount worker class to implement the application.

When I compile BankAccount.java I get this error:
BankAccount.java:89: error: cannot find symbol
return annualInterestRate;
^
symbol: variable annualInterestRate
location: class BankAccount
BankAccount.java:93: error: cannot find symbol
this.annualInterestRate = annualInterestRate;
^
symbol: variable annualInterestRate
2 errors

What does the error "cannot find symbol" mean? Perhaps if I fix that then Program2.java will work...
I've attached the 2 java and 1 class file if that helps.

Sorry. Forgot to change the file extension before uploading.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: How to troubleshoot "Exception in thread "main" java.lang.

Posted 20 September 2013 - 02:46 PM

So you've moved on to new errors.

That error means that the "symbol" or variable annualInterestRate has not been declared within the scope you've tried to use it. The compiler doesn't know what it is.
Was This Post Helpful? 1
  • +
  • -

#5 drunkfoo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-September 13

Re: How to troubleshoot "Exception in thread "main" java.lang.

Posted 24 September 2013 - 02:10 PM

Thanks Greg. That made sense and I was able to declare it. I've been playing around with the code to try to get it calculate the balance + interest when I use the yearly interest rate of 1.5 %. Currently the code expects the input of a monthly interest rate which is 0.00125%.

The instructions say "modify the BankAccount class's constructor method to create a BankAccount object which stores a monthly interest when the user inputs an annual interest rate of the format "nnn.nn"

Would this be the constructor that I'm supposed to alter in the BankAccount.java?:
public void addInterest()
{
interest = balance * interestRate;
balance += interest;
}

Would it be something like: interest = (balance * interestRate) /1200 ?
the balance will be $600 * 1.5 which equals 900 /1200 = .75 which is the interest result that I want because ultimately the balance output should be $600.75 (balance + interest)
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,204
  • Joined: 20-September 08

Re: How to troubleshoot "Exception in thread "main" java.lang.

Posted 24 September 2013 - 03:23 PM

Quote

There's little troubleshooting to do. The solution is to place the BankAccount.java source file where the compiler can find it, because the compiler can't find your BankAccount class.
That's a runtime error, not compile time
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1