This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

run time error Exception in thread "main" java.lang.NoSuchMethodError: main  RSS feed

 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am getting an error in run time in class creation.



code followed by



Error: [clrg@localhost check]$ javac MountainBike.java
[clrg@localhost check]$ java MountainBike
Exception in thread "main" java.lang.NoSuchMethodError: main
[clrg@localhost check]$


can any one help me? how to get the output ?
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are getting this ERROR because you don't have main method in your program. though the program compiles successfully, however when you run the program JVM needs main method as the entry point to run your program. since you don't have main method anywhere, you are getting above error. the solution would ofcourse would be to supply main method in one of the above classes. but better solution is to write a new class with main method
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have changed the code with main. but getting some errors in this if i use those main method. why is it giving errors after introducing the main method?


next code




errors during compilation time

MountainBike.java:9: illegal start of expression
public int seatHeight;
^
MountainBike.java:13: illegal start of expression
public MountainBike(int startHeight, int startCadence,
^
MountainBike.java:13: '.class' expected
public MountainBike(int startHeight, int startCadence,
^
MountainBike.java:13: ';' expected
public MountainBike(int startHeight, int startCadence,
^
MountainBike.java:13: <identifier> expected
public MountainBike(int startHeight, int startCadence,
^
MountainBike.java:14: not a statement
int startSpeed, int startGear) {
^
MountainBike.java:14: ';' expected
int startSpeed, int startGear) {
^
MountainBike.java:14: ';' expected
int startSpeed, int startGear) {
^
MountainBike.java:21: illegal start of expression
public void setHeight(int newValue) {
^
MountainBike.java:21: illegal start of expression
public void setHeight(int newValue) {
^
MountainBike.java:21: ';' expected
public void setHeight(int newValue) {
^
MountainBike.java:21: ';' expected
public void setHeight(int newValue) {
^
12 errors

How to solve this? and why is this error showing now and not prior ? can any one help me?
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see that you are having lots of compiler errors in your programs. also most of the things are related to java basics so i hightly recommend you to pick a good basic book of java and read it . i would recommend head first java . as far as your code is concerned in both the classes see that you have declared instance variables inside main method. remember that instance variables are declared in the class and NOT inside the methods. variables declared inside methods are LOCAL to the method. also local variables does not have any access modifier like public, private with them. infact the only modifier you can use with the local variable is final. also you have main method now in both the classes.
 
deepika deepi
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[quote=gurpeet singh

also you have main method now in both the classes.

i have taken out the method in Bicycle but getting the same method



But even get the same error.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that the same as the Bicycle class in the Java Tutorials?

Ddelete all your comments. Add a toString() method. Something like thisNow you want to make an application. An app should have two classes, so let’s create a BicycleDemo class. this ought to have the main method in. What follows is not ideal, since a main method should really consist of one statement.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!