Results 1 to 9 of 9
- 07-24-2008, 12:04 AM #1
Member
- Join Date
- Jul 2008
- Posts
- 2
- Rep Power
- 0
NoSuchMethodError : Main (isn't that a blatant lie)
I'm trying to create a random word generator based on a user input of "a"s and "b"s, I know I haven't validated the input yet, but what worries me is that it doesn't work at all, it just spits up an error, which t'interweb claims is very rare
Verbatum "Exception in thread "main" java.lang.NoSuchMethodError : main"
I don't understand what's wrong, code is below, all/any help is appreciated, thank you!
Java Code:import java.util.*; class CarolVordeman{ public static void main(String[] arguments) { String[] vowels = {"a", "e", "i", "o", "u"}; String[] consonants = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"}; Random generator = new Random(); int arraylength = arguments.length; String[] output = new String[arraylength]; for (int count=0; count < arguments.length; count++) { if (arguments[count] == a) { int r = generator.nextInt(5); output[count] = vowels[r]; } else { int r = generator.nextInt(21); output[count] = consonants[r]; } } System.out.println(); for (int count2=0; count2 < output.length; count2++) { System.out.print(output[count2]); } } }
- 07-24-2008, 02:43 AM #2
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
You have no Main Class. The compiler is looking for a Main Class. And in the Main Class it look for the Main Method. Thats why the COmpiler cannot find your Main Method because you dont have a Main Class ^_^
Here is my Suggestion:
Change this:
TO thisJava Code:class CarolVordeman{
I Hope that helpsJava Code:public class Main {Mind only knows what lies near the heart, it alone sees the depth of the soul.
- 07-24-2008, 03:20 AM #3
No, I don't think that you need a class by any given name.
Here's what I get when I try to execute a class that does NOT have a main method:
Check that the class file is correct and what you think it is.D:\JavaDevelopment\Testing>java Testing.WriteSerializedData
Exception in thread "main" java.lang.NoSuchMethodError: main
Copy and paste the console when you get the error.
- 07-24-2008, 06:38 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
For me the above code is ok, except one thing on the if statement, about comparing arguments array.
Back to the question, as Norm says it check the class name and the file name. But even in such a case you should comes with ClassNotFoundException. But here you get NoSuchMethodError. Anyway, check file name and class name.
- 07-24-2008, 08:33 AM #5
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
I stand corrected ^_^
I didnt get the error you got. here is the code. I Just fixed 1 line
It works fine for me. Here is my output:Java Code:import java.util.*; class CarolVordeman{ public static void main(String[] arguments) { String[] vowels = {"a", "e", "i", "o", "u"}; String[] consonants = {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"}; Random generator = new Random(); int arraylength = arguments.length; String[] output = new String[arraylength]; for (int count=0; count < arguments.length; count++) { if (arguments[count].equals("a")) { int r = generator.nextInt(5); output[count] = vowels[r]; } else { int r = generator.nextInt(21); output[count] = consonants[r]; } } System.out.println(); for (int count2=0; count2 < output.length; count2++) { System.out.print(output[count2]); } } }
Java Code:C:\>java CarolVordeman A 2 o 9 d phxds
Mind only knows what lies near the heart, it alone sees the depth of the soul.
- 07-24-2008, 10:56 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You fix the if condition, right? That's the only error I get too.
- 07-24-2008, 02:58 PM #7
Member
- Join Date
- Jul 2008
- Posts
- 2
- Rep Power
- 0
Works like a charm, you guys rock, cheers!
- 07-24-2008, 03:51 PM #8
It looks like the OP was getting a compiler error on the original program and didn't see. There was an old program class file with the same name that didn't have a main() method.
After doing a compile that failed, he tried to execute the old program and got the error.
When he fixed the program so that it compiles, the old version of the class file was replaced by the new code and it now works.
- 07-28-2008, 02:55 AM #9
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
Similar Threads
-
Arguments in Main
By CyberFrog in forum New To JavaReplies: 2Last Post: 03-30-2008, 09:37 PM -
main method
By eva in forum New To JavaReplies: 5Last Post: 12-19-2007, 09:25 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
exception in thred main java.lang.nosuchmethoderror: main
By fernando in forum Java AppletsReplies: 1Last Post: 08-06-2007, 09:11 AM -
Problem with main
By Hyder in forum Threads and SynchronizationReplies: 1Last Post: 04-28-2007, 10:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks