Run time error - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Run time error

ABDUL HAYEEABDUL HAYEE Posts: 81Member
Dear Sir ,
I am a beginner at java .It is my third program written for Student class .

I got it compiled normally , but am receiving a runtime exception .
It reads as :
Exception in the thread main
java. lang. NoSuchMethodError : main

I checked the code word by word , line by line , but I could not locate the error . Plz go through it and let me know where the error lies. ? Plz send me the code , if you need to modified it. Or let me know the steps , how should I proceed.

Code on Notepad as Java file :

/* 786 */
/* File Name Student.java */

public class Student {

private String name ;
private int rollNo ;

/* ***** Setters ****** */
public void setName ( String name){
this.name = name ;
}

/* ***** class lvel variable ***** */
public void setRollNo ( int rollNo ) {
if ( rollNo > 0 ) {
this.rollNo = rollNo ;
}
else {
this.rollNo = 100 ;
}
}

/* ***** standard getters ***** */
public String getName () {
return name ;
}

public int getRollNo () {
return rollNo ;
}

/* ***** Default constructor ***** */
public Student () {
name = " not set " ;
rollNo = 100 ;
}

/* ***** parameterized constructor for a new
student ***** */
public Student ( String name , int rollNo) {
setName (name) ;
setRollNo (rollNo) ;
}

/* ***** copy constructor for a new student ***** */
public Student ( Student s ) {
name = s.name ;
rollNo = s.rollNo ;
}

/* ***** method used to diplay on consol ***** */
public void print () {
System.out.print ( " Student name : " +name) ;
System.out.print ( " , roll no : " +rollNo) ;
}

} // ****** end of class


code ends here .


I have done as below :
Copied the code on notepad and saved as java file
Gave command < javac Student.java >
It worked / compiled successfully .
Gave command < java Student >
Got the Exception error.

Your help is solicited.
Thanks.




Comments

  • link2rajlink2raj Posts: 9Member
    from rajinder singh:
    dear frnd
    u have not write the main fn in the class as:
    public class Student {

    private String name ;
    private int rollNo ;

    /* ***** Setters ****** */
    public void setName ( String name){
    this.name = name ;
    }

    /* ***** class lvel variable ***** */
    public void setRollNo ( int rollNo ) {
    if ( rollNo > 0 ) {
    this.rollNo = rollNo ;
    }
    else {
    this.rollNo = 100 ;
    }
    }

    /* ***** standard getters ***** */
    public String getName () {
    return name ;
    }

    public int getRollNo () {
    return rollNo ;
    }

    /* ***** Default constructor ***** */
    public Student () {
    name = " not set " ;
    rollNo = 100 ;
    }

    /* ***** parameterized constructor for a new
    student ***** */
    public Student ( String name , int rollNo) {
    setName (name) ;
    setRollNo (rollNo) ;
    }

    /* ***** copy constructor for a new student ***** */
    public Student ( Student s ) {
    name = s.name ;
    rollNo = s.rollNo ;
    }

    /* ***** method used to diplay on consol ***** */
    public void print () {
    System.out.print ( " Student name : " +name) ;
    System.out.print ( " , roll no : " +rollNo) ;
    }
    //******************************
    public static void main(String args[])
    {
    Student std=new Student("rajinder",25);
    System.out.println(std.getName);//it will print ur name as rajinder
    System.out.println(std.getRollNo);// it will print ur rollno 25

    }
    //*******************************

    } // ****** end of class





  • ABDUL HAYEEABDUL HAYEE Posts: 81Member
    : from rajinder singh:
    : dear frnd
    : u have not write the main fn in the class as:
    : public class Student {
    :
    : private String name ;
    : private int rollNo ;
    :
    : /* ***** Setters ****** */
    : public void setName ( String name){
    : this.name = name ;
    : }
    :
    : /* ***** class lvel variable ***** */
    : public void setRollNo ( int rollNo ) {
    : if ( rollNo > 0 ) {
    : this.rollNo = rollNo ;
    : }
    : else {
    : this.rollNo = 100 ;
    : }
    : }
    :
    : /* ***** standard getters ***** */
    : public String getName () {
    : return name ;
    : }
    :
    : public int getRollNo () {
    : return rollNo ;
    : }
    :
    : /* ***** Default constructor ***** */
    : public Student () {
    : name = " not set " ;
    : rollNo = 100 ;
    : }
    :
    : /* ***** parameterized constructor for a new
    : student ***** */
    : public Student ( String name , int rollNo) {
    : setName (name) ;
    : setRollNo (rollNo) ;
    : }
    :
    : /* ***** copy constructor for a new student ***** */
    : public Student ( Student s ) {
    : name = s.name ;
    : rollNo = s.rollNo ;
    : }
    :
    : /* ***** method used to diplay on consol ***** */
    : public void print () {
    : System.out.print ( " Student name : " +name) ;
    : System.out.print ( " , roll no : " +rollNo) ;
    : }
    : //******************************
    : public static void main(String args[])
    : {
    : Student std=new Student("rajinder",25);
    : System.out.println(std.getName);//it will print ur name as rajinder
    : System.out.println(std.getRollNo);// it will print ur rollno 25
    :
    : }
    : //*******************************
    :
    : } // ****** end of class
    :
    :
    : ..................................................................
    : Dear Rajinder ,
    : It was pinching that I had not written the main function , but I was unable to compose , what should I write there. The print function had already been called in prevoious line , and I did not know what alse to write.
    : But I hope it will work now . I will let you know , hopefully by tomorrow evening. Presently I am stuck with an assignment on computer graphics.

    Many thanks again.
Sign In or Register to comment.