Search code examples
javaexceptionnoclassdeffounderror

exception in thread "main" with java.lang.noclassdeffounderror


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)

Solution

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