Results 1 to 13 of 13
Thread: please help
- 02-02-2011, 04:36 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
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);
}
}
- 02-02-2011, 04:39 AM #2
You are trying to run a class called "simple_interest" but the actual class is called a1. The names must match.
- 02-02-2011, 04:44 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
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);
}
}
- 02-02-2011, 04:48 AM #4
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
thx error solved
- 02-02-2011, 04:48 AM #5
Are you trying to run from the command line? If so the commands are
Java Code://compile javac ProgramName.java //run java ProgramName
- 02-02-2011, 05:02 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
how can i write this in efficient way
- 02-02-2011, 05:03 AM #7
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
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);
}
}
- 02-02-2011, 05:04 AM #8
Java is case sensitive. New is not the same as new.
- 02-02-2011, 06:51 AM #9
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
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);
}
}
- 02-02-2011, 07:03 AM #10
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
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.
- 02-02-2011, 07:14 AM #11
Member
- Join Date
- Feb 2011
- Posts
- 10
- Rep Power
- 0
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>
- 02-02-2011, 08:45 AM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Are you planning on posting each compilation big here and expecting us to fix it?
- 02-02-2011, 09:46 AM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks