Exception / error - Programmers Heaven

Howdy, Stranger!

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

Categories

Exception / 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

  • zibadianzibadian Posts: 6,349Member
    : 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.
    :
    :
    :
    Where is your main() method? Every java programs [b]must[/b] define a main() method.
Sign In or Register to comment.