Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Run time error Posted by ABDUL HAYEE on 19 Oct 2006 at 2:33 AM
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.




Report
Re: Run time error Posted by link2raj on 26 Oct 2006 at 4:57 PM
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





Report
Re: Run time error Posted by ABDUL HAYEE on 27 Oct 2006 at 1:50 PM
: 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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.