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...
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);
}
}
}
Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main
Quote:
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.
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
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.
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..
Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main
Quote:
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.
Re: Error:Exception in thread "main" java.lang.NoSuchMethodError:main
Thank you.....got the answer :(happy):