Results 1 to 6 of 6

Thread: Getting many Errors when trying to run the Java Program

  1. #1
    Join Date
    Aug 2006
    Posts
    300

    Getting many Errors when trying to run the Java Program

    I am new to Java programming language. Now when I try to run the Java Program many Errors are pops out. Some are like the
    'java.lang.NoClassDefFoundError: Mortgage
    Caused by: java.lang.ClassNotFoundException: Mortgage
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)' etc...
    I don't know where I am going wrong.!! Do anyone have idea how to isolate this errors.?? Please help me soon..!!

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Getting many Errors when trying to run the Java Program

    The Error "java.lang.NoClassDefFoundError: Mortgage" gets generated when it could not found the class called "Mortgage". Tell how you are running your java program?? Also it would be better if you provide the Code and your Compiler or IDE that you are using.! Make sure that your filename matches the class name, in this case you should have a Mortgage.java file, that contains the class definition for it. I think that you should have a line like public class Mortgage { ... } Since it is case sensitive, you must have the M in Mortgage capitalized if you are matching the filename to the class name in the file.

  3. #3
    Join Date
    Aug 2006
    Posts
    300

    Re: Getting many Errors when trying to run the Java Program

    Thanks for replying 'Praetor'. Here is my code of Java program :

    import java.io.*;
    import java.text.NumberFormat;

    public class Mortgage {

    public static void main(String args[]) throws IOException {

    BufferedReader keyboard =
    new BufferedReader(new InputStreamReader(System.in));
    double principal, rate, ratePercent;
    int years, n;
    final int paymentsPerYear = 12;
    final int timesPerYearCalculated = 12;
    double effectiveAnnualRate;
    double payment;
    NumberFormat currency = NumberFormat.getCurrencyInstance();

    System.out.print("How much money are you borrowing? ");
    principal = Double.parseDouble(keyboard.readLine());
    System.out.print("What's the interest rate? ");
    ratePercent = Double.parseDouble(keyboard.readLine());
    rate = ratePercent / 100.00;
    System.out.print("How many years are you taking to pay? ");
    years = Integer.parseInt(keyboard.readLine());
    System.out.println("------------------------------");

    n = paymentsPerYear * years;
    effectiveAnnualRate = rate / paymentsPerYear;
    payment =
    principal
    * (effectiveAnnualRate
    / (1 - Math.pow(1 + effectiveAnnualRate, -n)));
    System.out.print("Your monthly payment is ");
    System.out.println(currency.format(payment));
    System.out.println();
    }
    }

    Also I am using the JCreator LE as my Compiler. Hope that some can help me.!!

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Getting many Errors when trying to run the Java Program

    I think that there is problem with the compiler. Anyway you can try this :
    First open the JCreator. Then go to the File >> New >> File. From here select the "Empty Java File" on the right and the "Java Classes" on the left. Then Click next. Fill in name : HelloWorld and then click on "....." button after Location field and select "Desktop" and click "OK" Then click finish. Now a titled "HelloWorld.java" new tab should be opened. The code should be :

    public class HelloWorld
    {
    public static void main(String[] args)
    {
    System.out.println("Hello World!");
    }
    }
    Copy your code in, compile and run.
    Make sure it says "public class HelloWorld" (a "public class" has to match the filename). If this works properly, then i would recommend that until you need to create a project you should create your source code like this for a while.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Getting many Errors when trying to run the Java Program

    The Error message "NoClassDefFoundError" comes when you try to Run your program without having the classfile. Many times it happens that before compiling the program, we try to execute the program unknowingly. So be sure that you have compiled the project before you try to run it. Also try to make a project in that workspace. You can do this by going in File. From File select the option New. Then select the Project for creating new project. Then add your source code to that project. Maybe this works.

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Getting many Errors when trying to run the Java Program

    You should follow the steps that I have mentioned to isolate the Error.
    Start doing the steps after logging in as an Administrator user. Go to the Run by clicking the Start button. And in the open box specify your Java Bin folder. Then click on the Javac.exe and then copy the link. After that open your Compiler i.e. JCreator. In that go to the JDK tools by selecting the menu configure, & option. Now click on the edit tab and then paste your link. Again go to the Run and specify the Java Bin folder. Then click on the Java.exe and copy the link. Again follow the procedure for going to the JDK tools, then paste the link after clicking on the edit. Now instead of compiler click on Run. click on default and edit then paste your link then click on OK. And then compile the file. I think that this time you will not get an error.

Similar Threads

  1. Dr. Java program
    By bamggut29 in forum Software Development
    Replies: 2
    Last Post: 26-11-2011, 04:24 AM
  2. How are exceptions and errors handled in a program ?
    By Hemendu in forum Software Development
    Replies: 6
    Last Post: 07-12-2010, 11:33 PM
  3. Java applet errors
    By Harpreet Gaur in forum Software Development
    Replies: 5
    Last Post: 12-01-2010, 12:08 PM
  4. Class, interface errors in my program
    By Balamani in forum Software Development
    Replies: 3
    Last Post: 02-12-2009, 06:26 PM
  5. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,827,913.48352 seconds with 16 queries