Results 1 to 5 of 5
  1. #1
    kjharn is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default 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:
    Java Code:
    public static int main (String args[])
    The program compiles correctly, naturally, but when executing it says this:
    Java Code:
    Exception in thread "main" java.lang.NoSuchMethodError: main
    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.

    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;
    	}
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Your instructor is on drugs. The main method must be void.
    It must not return an int.

  3. #3
    kjharn is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    Figures. Now that I fixed that, just gotta figure out an easier way to convert oct to dec... Also one that works...

    Thanks!

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,775
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by r035198x View Post
    the silly user
    That is a tautology.

    kind regards,

    Jos ;-)

Similar Threads

  1. [error] java.lang.NoSuchMethodError: main
    By jon80 in forum New To Java
    Replies: 1
    Last Post: 04-30-2009, 12:21 AM
  2. .BAT execution error
    By hunterbdb in forum Advanced Java
    Replies: 5
    Last Post: 02-23-2009, 06:41 AM
  3. NoSuchMethodError : Main (isn't that a blatant lie)
    By havfunonline in forum New To Java
    Replies: 8
    Last Post: 07-28-2008, 03:55 AM
  4. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  5. Replies: 1
    Last Post: 08-06-2007, 10:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •