• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76450
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic