• Post Reply Bookmark Topic Watch Topic
  • New Topic

simple code of 7  RSS feed

 
Arthur Okeke
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello every one and goodday
i just wanna know why this code won,t run it just gave me
Exception in thread "main" java.lang.NoSuchMethodError: main

public class An {
public static void int() {
int x = 6; // assign 6 to x
while (x > 2) {
//loop code will run
//for x is greater than 2
x = x-1;
}
}
}
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error tells you exactly what's wrong. It can't find a main method, i.e., the starting point of your program. Programs can't just start from nowhere.

Declare a method in your class with the following signature: "public static void main(String[] args)"
 
Arthur Okeke
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have adjusted it thus

public class An {
public static void main(string[] args) {
int x = 6; // assign 6 to x
while (x > 2) {
//loop code will run
//for x is greater than 2
x = x-1;
}
}
}

but its giving the same error
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags.

I doubt your current code would compile at all. Have you recompiled your code? you should get a different error.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please check your code properly... Its fine only... Make it as (String[] args)
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it is giving you the same error? The error that you should have something else.
Hing: Look at your main method line. Java is case sensitive.
Also, please use code tag when putting out code. It's much easier to read.

Good Luck!
Gary
 
Arthur Okeke
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


please someone should run this its still giving errors and i have checked
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now you've got "public" capitalized in two places, when it should be lower case, and "String" is lower case still, when it should be upper case. Also you've got what looks like a variable declaration for "x", but you didn't include the variable name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!