Results 1 to 5 of 5
- 11-02-2009, 06:44 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
Execution error: NoSuchMethodError: Main
Hello all,
I have an assignment due (today, of course) and the instructor outlines in the assignment sheet that we need to declare main using:
The program compiles correctly, naturally, but when executing it says this:Java Code:public static int main (String args[])
Normally this error is pretty simple to diagnose, since usually in that case main is missing entirely. Anyways, I realize there are some logical errors in this programs, and some overly complex ways of doing things... Gotta do it the way the instructor says.Java Code:Exception in thread "main" java.lang.NoSuchMethodError: main
Can anyone shed some light on this problem? Thanks a lot guys
Heres the complete code:
Java Code:import java.util.Scanner; public class kharnden_Decimal { static int con; public static int main( String args[] ) { Scanner sc = new Scanner(System.in); System.out.print("Enter a positive number up to 8 digits (Fmt: 00000000)"); con = sc.nextInt(); System.out.print(con + ":" + convert(con)); return con; } public static int convert ( int octalNumber) { int d1, d2, d3, d4, d5, d6, d7, d8; String in = Integer.toString(con); d1 = in.charAt(0) - 48; d2 = in.charAt(1) - 48; d3 = in.charAt(2) - 48; d4 = in.charAt(3) - 48; d5 = in.charAt(4) - 48; d6 = in.charAt(5) - 48; d7 = in.charAt(6) - 48; d8 = in.charAt(7) - 48; con = (d1 * 8^7) + (d2 * 8^6) + (d3 * 8^5) + (d4 * 8^4) + (d5 * 8^3) + (d6 * 8^2) + (d7 * 8^1) + (d8 * 8^0); return con; } }
- 11-02-2009, 06:46 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Your instructor is on drugs. The main method must be void.
It must not return an int.
- 11-02-2009, 06:58 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
Figures. Now that I fixed that, just gotta figure out an easier way to convert oct to dec... Also one that works...
Thanks!
- 11-02-2009, 07:14 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What happens if the silly user enters a 3 digit number (or any n<8 digit number)?
Better split that string into characters using the String.toCharArray method. Then you can loop through the array form the last position moving to the left.
P.S You could also simply cheat and use Integer.toString() method that takes two int arguments. Read the API specs for it.
- 11-02-2009, 08:23 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
[error] java.lang.NoSuchMethodError: main
By jon80 in forum New To JavaReplies: 1Last Post: 04-29-2009, 11:21 PM -
.BAT execution error
By hunterbdb in forum Advanced JavaReplies: 5Last Post: 02-23-2009, 05:41 AM -
NoSuchMethodError : Main (isn't that a blatant lie)
By havfunonline in forum New To JavaReplies: 8Last Post: 07-28-2008, 02:55 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


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks