Results 1 to 13 of 13

Thread: please help

  1. #1
    Azaz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Exclamation please help

    Exception in thread "main" java.lang.NoClassDefFoundError: simple_inter
    Caused by: java.lang.ClassNotFoundException: simple_interest
    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)
    Could not find the main class: simple_interest. Program will exit.

    here is the code :-

    class a1
    {
    public static void main(String args[])
    {
    System.out.println("Enter Principal amount : ");
    int p=Integer.parseInt(args[0]);
    System.out.println("Enter Rate of Interest : ");
    int r=Integer.parseInt(args[1]);
    System.out.println("Enter No. of years : ");
    int n=Integer.parseInt(args[2]);
    int si=(p*r*n)/100;
    System.out.println("Simple Interest = "+si);
    }
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    You are trying to run a class called "simple_interest" but the actual class is called a1. The names must match.

  3. #3
    Azaz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Exclamation After Edited

    Caused by: java.lang.ClassNotFoundException: simple_interest.java
    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)
    Could not find the main class: simple_interest.java. Program will exit.

    here is code :-

    class simple_interest
    {
    public static void main(String args[])
    {
    System.out.println("Enter Principal amount : ");
    int p=Integer.parseInt(args[0]);
    System.out.println("Enter Rate of Interest : ");
    int r=Integer.parseInt(args[1]);
    System.out.println("Enter No. of years : ");
    int n=Integer.parseInt(args[2]);
    int si=(p*r*n)/100;
    System.out.println("Simple Interest = "+si);
    }
    }

  4. #4
    Azaz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Smile

    thx error solved

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Are you trying to run from the command line? If so the commands are
    Java Code:
    //compile
    javac ProgramName.java
    
    //run
    java ProgramName

  6. #6
    Azaz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default

    how can i write this in efficient way

  7. #7
    Azaz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default

    compiling: simple_interest.java
    simple_interest.java(6): ';' expected.
    DataInputStream x= New DataInputStream(system.in);

    here is the code :-

    import java.io.*;
    class simple_interest
    {
    public static void main(String args[])throws IOException
    {
    DataInputStream x= New DataInputStream(system.in);
    System.out.println("Enter Principal amount : ");
    int p=Integer.parseInt(x.readline());
    System.out.println("Enter Rate of Interest : ");
    int r=Integer.parseInt(x.readline());
    System.out.println("Enter No. of years : ");
    int n=Integer.parseInt(x.readline());
    float si=(p*r*n)/100;
    System.out.println("Simple Interest = "+si);
    }
    }

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Java is case sensitive. New is not the same as new.

  9. #9
    Azaz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default

    compiling: simple_interest.java
    simple_interest.java(8): Method Readline() not found in class java.io.DataInputS
    tream.
    int p=Integer.parseInt(x.Readline());
    ^
    simple_interest.java(10): Method Readline() not found in class java.io.DataInput
    Stream.
    int r=Integer.parseInt(x.Readline());
    ^
    simple_interest.java(12): Method Readline() not found in class java.io.DataInput
    Stream.
    int n=Integer.parseInt(x.Readline());
    ^
    3 errors

    here is the code after Editing :-

    import java.io.*;
    class simple_interest
    {
    public static void main(String args[])throws IOException
    {
    DataInputStream x=new DataInputStream(System.in);
    System.out.println("Enter Principal amount : ");
    int p=Integer.parseInt(x.readline());
    System.out.println("Enter Rate of Interest : ");
    int r=Integer.parseInt(x.readline());
    System.out.println("Enter No. of years : ");
    int n=Integer.parseInt(x.readline());
    int si=(p*r*n)/100;
    System.out.println("Simple Interest = "+si);
    }
    }

  10. #10
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    Please post your code in [code][/code] tags. It makes it that much easier to read.

    You're trying to call the method "Readline", which doesn't exist. You might be looking for the deprecated method "readLine" - again, note the different capitalisation - but you'd be better off looking for a non-deprecated one. Here's the API.

  11. #11
    Azaz is offline Member
    Join Date
    Feb 2011
    Posts
    10
    Rep Power
    0

    Default

    compiling: simple_interest.java
    simple_interest.java(8): Method readline() not found in class java.io.DataInputS
    tream.
    int p=Integer.parseInt(x.readline());
    ^
    simple_interest.java(10): Method readline() not found in class java.io.DataInput
    Stream.
    int r=Integer.parseInt(x.readline());
    ^
    simple_interest.java(12): Method readline() not found in class java.io.DataInput
    Stream.
    int n=Integer.parseInt(x.readline());
    ^
    3 errors

    here is the code after editing :-
    <code>
    import java.io.*;
    class simple_interest
    {
    public static void main(String args[])throws IOException
    {
    DataInputStream x=new DataInputStream(System.in);
    System.out.println("Enter Principal amount : ");
    int p=Integer.parseInt(x.readline());
    System.out.println("Enter Rate of Interest : ");
    int r=Integer.parseInt(x.readline());
    System.out.println("Enter No. of years : ");
    int n=Integer.parseInt(x.readline());
    int si=(p*r*n)/100;
    System.out.println("Simple Interest = "+si);
    }
    }
    </code>

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,086
    Rep Power
    20

    Default

    Are you planning on posting each compilation big here and expecting us to fix it?

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Tolls View Post
    Are you planning on posting each compilation big here and expecting us to fix it?
    Cool! We'll be the online compiler; I do the parsing, you do the tokening and somebody else can do the code generation!

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •