0

it says exeption it thread "main" java.lang.noclassdeffounderror: followed by thirteen lines of "at java."

ive tried the most common ways to solve this error, im completely new to java and this is driving me nuts! its very discouraging. :( i changed the "classpath" environment variable to a "." and copied the correct path (C:\Program Files\Java\jdk1.7.0_17\bin) to the "path" variable as well. i dont think its that. i even tried it on a different computer with the exact same results (after i changed the environment variables). and i downloaded the code from the "fordummies" website so i dont think its bad code... Ive spent the last 4 hours researching this, i guess its time to turn to the experts for advice :) :)

// This program prompts for information about a loan and
// computes the monthly loan payment.

import java.util.*;   // for Scanner

public class Mortgage {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);

        // obtain values
        System.out.println("This program computes monthly " +
                           "loan payments.");
        System.out.print("loan amount     : ");
        double loan = console.nextDouble();
        System.out.print("number of years : ");
        int years = console.nextInt();
        System.out.print("interest rate   : ");
        double rate = console.nextDouble();
        System.out.println();

        // compute result and report
        int n = 12 * years;
        double c = rate / 12.0 / 100.0;
        double payment = loan * c * Math.pow(1 + c, n) /
                         (Math.pow(1 + c, n) - 1);
        System.out.println("payment = $" + (int) payment);
    }
}

THE ERROR IS:

at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(unknown Source)
    at java.security.AccessController.DoPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
alexbt
  • 16,415
  • 6
  • 78
  • 87
0000
  • 677
  • 2
  • 8
  • 20
  • 4
    Please show *exactly* what the error message is, and *exactly* how you're trying to run it. – Jon Skeet Mar 28 '13 at 20:39
  • What commands are you running at the command line? – Matthew T. Staebler Mar 28 '13 at 20:39
  • possible duplicate of [Why am I getting a NoClassDefFoundError in Java?](http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java) – D.Shawley Mar 28 '13 at 20:39
  • Are you running it from the command-line of from inside Eclipse or other IDE? – PM 77-1 Mar 28 '13 at 20:46
  • @D.Shawley - While it's not a duplicate, OP could hopefully benefit from the answers to the question you have provided the link for. – PM 77-1 Mar 28 '13 at 20:49
  • file that is the pic of what the error is. i know there are a million people who have asked the same question, but i think the problem might be unique, so i figured id ask. i cant believe i got answers so fast! :) – 0000 Mar 28 '13 at 21:07
  • @musicman_385: your link appears to be broken, should it be https://skydrive.live.com/?ppud=4#cid=547B49A27FFCC19D&id=547B49A27FFCC19D!166 ? There was nothing that I have permission to view when I followed that link. Can you not copy and paste the text of the error into your question, rather than post a link to an image that nobody other than you can view, if it exists at all? – Luke Woodward Mar 28 '13 at 21:15
  • @musicman_385, all I see on that page is the word "Error" and a outgoing link. You're running this from the command line, right? So you can edit your question and paste in the stack trace you're getting. – Ladlestein Mar 28 '13 at 21:16
  • crap, sorry about that. i feel like an idiot lol, yes i am running this from the command prompt. i tried to "java mortgage > C:\output.text" to dump the error in a text file but its not working, i really dont want to type it all out lol. im sorry if i sound stupid. – 0000 Mar 28 '13 at 21:29
  • I just typed it by hand, pasted it above ^^ – 0000 Mar 28 '13 at 22:07
  • Try "java mortgage 2>&1 output.txt" to capture the complete error message. – Code-Apprentice Mar 28 '13 at 22:44
  • @Code-Guru it says handle cannot be duplicated during redirection of handle 1. im sorry im still new to all of this. :) – 0000 Mar 28 '13 at 23:03
  • 1
    @musicman_385: you haven't pasted the entire error. Presumably you know how to copy text from a command prompt (http://www.howtogeek.com/howto/windows-vista/copy-to-the-clipboard-from-the-windows-command-prompt/)? – Luke Woodward Mar 28 '13 at 23:04
  • `java mortgage 2> output.txt` should work for just the error output. With my original suggestion, I was trying to get all output just in case. – Code-Apprentice Mar 28 '13 at 23:07
  • @Code-Guru YOUR A GENIUS! such a simple solution! THANK YOU FOR YOUR HELP MAN!!! and thank you for helping me with such a noob problem hahaha ;) – 0000 Mar 28 '13 at 23:11
  • If my answer solved your problem, please accept it by clicking the checkmark. And welcome to SO! – Code-Apprentice Mar 28 '13 at 23:17

2 Answers2

1

Note that Java is case sensitive, including the arguments used at the command line. My guess is that you are running your program incorrectly with

java mortgage

Since your class name is Mortgage, you must use the same capitalization:

java Mortgage

Note that the java program expects the name of the class which contains the main() method. Because of this, the capitalization must match what you declared in your code.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
0

I don't know if this is the problem but its worth a try.

First off (this is what I'm not sure about) I think that instead of:

public static void main(String[] args)

I think that you should have:

public static void main(String args[]){}

Another thing is make sure that you have you manifest.txt file if you are making your program a Jar file. Some information on Jar manifest files.

Liam15
  • 75
  • 1
  • 6