Results 1 to 7 of 7
- 01-20-2012, 05:51 AM #1
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
- 01-20-2012, 05:54 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main
That code does not give that error. Because it does not compile.it shows the error as "Exception in thread "main" java.lang.NoSuchMethodError:main"
Try compiling it again. If you do not understand the compiler's messages, post them.
- 01-20-2012, 06:05 AM #3
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
- 01-20-2012, 06:20 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
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.
- 01-20-2012, 09:39 AM #5
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..
- 01-20-2012, 11:55 PM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main
*What* shows the error? That is, what is the code you are using now?but it shows the same exception error
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.
- 01-21-2012, 05:59 AM #7
Similar Threads
-
Exception in thread "main" java.lang.NoSuchMethodError: main
By Bibin in forum New To JavaReplies: 1Last Post: 12-24-2011, 08:45 AM -
Exception in thread "main" java.lang.NoSuchMethodError: main
By ravifedora in forum New To JavaReplies: 28Last Post: 03-16-2011, 07:06 PM -
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks