Results 1 to 12 of 12
  1. #1
    Join Date
    Sep 2010
    Posts
    18
    Rep Power
    0

    Default 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

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,440
    Blog Entries
    7
    Rep Power
    20

    Default

    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,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Join Date
    Sep 2010
    Posts
    18
    Rep Power
    0

    Default

    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

  4. #4
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    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?

    student1 stud=new student1();
    Where is your constructor?There is no need of this line I think.

    Be confident about this lines
    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);
    You can use Scanner class for taking inputs from keyboard.

    Regards
    Ujjal
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  5. #5
    Join Date
    Sep 2010
    Posts
    18
    Rep Power
    0

    Default

    please guide on creating objects and using them to invoke functions within the same class and outside with example code.

  6. #6
    Join Date
    Sep 2010
    Posts
    18
    Rep Power
    0

    Default

    yes i did save the file as student1.java

  7. #7
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    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();
    } 
    
    }
    Why I am writing this code here? I think you already know this...
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

  8. #8
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    There is nothing wrong with your code.
    The error is in how you type it in the command line:
    Java Code:
    javac Student1.java
    //compiles file
    java Student1
    //runs program
    You do not add ".java" at the end of the class name when running it.

  9. #9
    to_devendra is offline Member
    Join Date
    Apr 2011
    Posts
    7
    Rep Power
    0

    Default

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

  10. #10
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    @to_devendra
    we have already clarified that. please read earlier comments before posting anything next time.

  11. #11
    Join Date
    Sep 2010
    Posts
    18
    Rep Power
    0

    Default

    thanks a lot :)

  12. #12
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Similar Threads

  1. JPA application noclassdeffound error
    By ishakteyran in forum New To Java
    Replies: 2
    Last Post: 03-12-2010, 07:31 PM
  2. JPA application noclassdeffound error
    By ishakteyran in forum Advanced Java
    Replies: 2
    Last Post: 03-11-2010, 01:14 AM
  3. JPA application noclassdeffound error
    By ishakteyran in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 03-11-2010, 12:34 AM
  4. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  5. java.lang.NoClassDefFound --Any way to handle this
    By sunny_sykes in forum Advanced Java
    Replies: 1
    Last Post: 03-30-2009, 08:29 AM

Posting Permissions

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