Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Error:Exception in thread "main" java.lang.NoSuchMethodError:main

    I need to take the screeshot using java programming...have used the code below...but it shows the error as "Exception in thread "main" java.lang.NoSuchMethodError:main"....can anyone help me in resolving the problem...

    Java Code:
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    import java.io.File;
     public class ScreenShot
    {
       public static void main(String[] args)
    	{
            public void captureScreen(String fileName) throws Exception 
    	 {
     
    		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    		Rectangle screenRectangle = new Rectangle(screenSize);
    		Robot robot = new Robot();
    		BufferedImage image = robot.createScreenCapture(screenRectangle);
    		ImageIO.write(image, "png", new File(screen);
     
    	 }
           }
    }
    Last edited by pbrockway2; 01-20-2012 at 06:16 AM. Reason: code tags added

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main

    it shows the error as "Exception in thread "main" java.lang.NoSuchMethodError:main"
    That code does not give that error. Because it does not compile.

    Try compiling it again. If you do not understand the compiler's messages, post them.

  3. #3
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main

    It shows an error--illegal start of expression in the line public void captureScreen(String fileName) throws Exception...can you help me out....Thanks for response

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main

    "illegal start of expression" means you have written something on that line that doesn't make sense as Java - in this case it is the keyword "public" that the compiler is objecting to. That's because you are attempting to define a method screenCapture() inside another method, main(). And you can't do that.

  5. #5
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main

    ohh thanks...now i could not able to subject any error during compilation..but it shows the same exception error while trying to run the code....can you provide the correct code or any link suggesting about screen shot..

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main

    but it shows the same exception error
    *What* shows the error? That is, what is the code you are using now?

    Also since you are getting an error when you attempt to start the program it would be a good idea to describe how you are starting the program - the command you use at the command line for instance.

  7. #7
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main

    Thank you.....got the answer

Similar Threads

  1. Replies: 1
    Last Post: 12-24-2011, 08:45 AM
  2. Replies: 28
    Last Post: 03-16-2011, 07:06 PM
  3. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  4. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:10 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
  •