Results 1 to 12 of 12
Thread: java.lang.NoClassDefFound error
- 04-12-2011, 06:36 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 18
- Rep Power
- 0
java.lang.NoClassDefFound error
[B][B]a program to calculate avg of students:
import java.util.*;
import java.io.*;
public class student1
{
public static void main(String a[]) throws IOException
{
int m1,m2,m3,m4,sum,avg;
try
{
DataInputStream g=new DataInputStream(System.in);
m1=Integer.parseInt(g.readLine());
m2=Integer.parseInt(g.readLine());
m3=Integer.parseInt(g.readLine());
m4=Integer.parseInt(g.readLine());
System.out.println("enter the marks of 4 subjects");
avg=g.display(m1,m2,m3,m4);
System.out.println("result is:"+avg);
}
catch(Exception e)
{
System.out.println("error");
}
}
}
class display1
{
public double display(int mk1,int mk2,int mk3,int mk4)
{
double avrg;
avrg=(mk1+mk2+mk3+mk4)/4;
return avrg;
}
}
the error is as follows pls help:confused:
student1.java:17: cannot find symbol
symbol : method display(int,int,int,int)
location: class student1
avg=stud.display(m1,m2,m3,m4);
^
Note: student1.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
- 04-12-2011, 06:42 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
The code you have shown us is not the code you tried to compile or you have made up the compiler error message. Don't try to fool us and be exact about what's causing you problems.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-13-2011, 03:30 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 18
- Rep Power
- 0
sorry for the trouble..
here is the code
import java.io.*;
public class student1
{
public static void main(String a[]) throws IOException
{
int m1,m2,m3,m4,sum,avg;
student1 stud=new student1();
try
{
DataInputStream g=new DataInputStream(System.in);
m1=Integer.parseInt(g.readLine());
m2=Integer.parseInt(g.readLine());
m3=Integer.parseInt(g.readLine());
m4=Integer.parseInt(g.readLine());
System.out.println("enter the marks of 4 subjects");
stud.display(m1,m2,m3,m4);
}
catch(Exception e)
{
System.out.println("error");
}
}
private void display(int m1, int m2, int m3, int m4)
{
int avrg;
avrg=(m1+m2+m3+m4)/4;
System.out.println("result is:"+avrg);
}
}
the error msg:
C:\Users\swathi>path C:\Program Files (x86)\Java\jdk1.6.0_03\bin
C:\Users\swathi>javac student1.java
Note: student1.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\swathi>java student1.java
Exception in thread "main" java.lang.NoClassDefFoundError: student1/java
- 04-13-2011, 04:07 PM #4
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
You are working on main() method. In netbeans there is no compilation error.But may be some bugs in your code.
Did you save your source code name as student1.java?
Where is your constructor?There is no need of this line I think.student1 stud=new student1();
Be confident about this lines
You can use Scanner class for taking inputs from keyboard.DataInputStream g=new DataInputStream(System.in);
m1=Integer.parseInt(g.readLine());
m2=Integer.parseInt(g.readLine());
m3=Integer.parseInt(g.readLine());
m4=Integer.parseInt(g.readLine());
System.out.println("enter the marks of 4 subjects");
stud.display(m1,m2,m3,m4);
Regards
UjjalDon't Forget to try yourself before asking others help.....
Press REP, if you find their advices/solutions effective.
- 04-13-2011, 05:17 PM #5
Member
- Join Date
- Sep 2010
- Posts
- 18
- Rep Power
- 0
please guide on creating objects and using them to invoke functions within the same class and outside with example code.
- 04-13-2011, 05:18 PM #6
Member
- Join Date
- Sep 2010
- Posts
- 18
- Rep Power
- 0
yes i did save the file as student1.java
- 04-13-2011, 05:48 PM #7
Senior Member
- Join Date
- Apr 2010
- Location
- Dhaka,Bangladesh
- Posts
- 178
- Rep Power
- 0
Why I am writing this code here? I think you already know this...Java Code://student1.java/// class classname1{ public classname1(){ //write your code here constructor } }; public class student1{ public static void main(String a[]){ //create instances here classname1 object=new classname1(); } }Don't Forget to try yourself before asking others help.....
Press REP, if you find their advices/solutions effective.
- 04-13-2011, 09:56 PM #8
There is nothing wrong with your code.
The error is in how you type it in the command line:
You do not add ".java" at the end of the class name when running it.Java Code:javac Student1.java //compiles file java Student1 //runs program
- 04-13-2011, 10:38 PM #9
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
this is wrong
avg=g.display(m1,m2,m3,m4);
that should be as below
display1 dis=new display1();
avg=dis.display(m1,m2,m3,m4);
int avg
should be
double avg;
now , your code will work...
- 04-14-2011, 12:26 AM #10
@to_devendra
we have already clarified that. please read earlier comments before posting anything next time.
- 04-14-2011, 01:23 PM #11
Member
- Join Date
- Sep 2010
- Posts
- 18
- Rep Power
- 0
thanks a lot :)
- 04-14-2011, 06:33 PM #12
Similar Threads
-
JPA application noclassdeffound error
By ishakteyran in forum New To JavaReplies: 2Last Post: 03-12-2010, 07:31 PM -
JPA application noclassdeffound error
By ishakteyran in forum Advanced JavaReplies: 2Last Post: 03-11-2010, 01:14 AM -
JPA application noclassdeffound error
By ishakteyran in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 03-11-2010, 12:34 AM -
Thread: Error 500--Internal Server Error java.lang.NullPointerException
By jackdear44 in forum New To JavaReplies: 1Last Post: 12-05-2009, 07:28 AM -
java.lang.NoClassDefFound --Any way to handle this
By sunny_sykes in forum Advanced JavaReplies: 1Last Post: 03-30-2009, 08:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks