To make it short and sweet, here it is. Looking to do a simple screenshot on the client-side (and if anyone would be so kind, point me in the direction to create an automated upload of the screen to a server. ++ if you can provide a tip on doing this at an interval)..

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ScreenShot {
/**
method to capture screen shot
@param String uploadPath to save screen shot as image
@returns boolean true if capture successful else false
*/
boolean captureScreenShot(String uploadPath) 
{
boolean isSuccesful = false;
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture;
try {
capture = new Robot().createScreenCapture(screenRect);
// screen shot image will be save at given path with name "screen.jpeg"
ImageIO.write(capture, "jpg", new File( uploadPath, "screen.jpeg")); 
isSuccesful = true;
} catch (AWTException awte) {
awte.printStackTrace();
isSuccesful = false;
}
catch (IOException ioe) {
ioe.printStackTrace();
isSuccesful = false;
}
return isSuccesful;
}
}

Here's what I did: Took the screenshot java file made from above and compiled it, but here's the error I get when I try to run the class in java..

java ScreenShot

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

What is going wrong? And I'm a little confused with the upload path part, is that a constant, a placeholder prompting the user to submit a string, can that designation be pointed to a server?

Thanks to all that can help. : )

Recommended Answers

All 14 Replies

java.lang.NoSuchMethodError: main

You need to provide the standard main() method in the class that you try to execute with the java command.

Thank you for your help, and umm anything on the path bit I touched on there?

the path bit

Please explain.

boolean captureScreenShot(String uploadPath)

ImageIO.write(capture, "jpg", new File( uploadPath, "screen.jpeg"));

Am I supposed to supply one? or is it a constant that's set? Can I point it to an environment online?

EDIT ignore the periods, was just trying to insert the correct arrow placement as per the cmd line results

Getting new problems now that I supplied main.

Screenshot.java:16: ';' expected

boolean captureScreenShot(String uploadPath)
............................................^

Screenshot.java:16: ';' expected

boolean captureScreenShot(String uploadPath)
..........................................................................^

I'm super confused, I'm way more of a server side guy.

could you post your current code now with main

I really didn't do anything special, I enclosed the whole thing, starting with the first boolean in the 'public static void main(String [] args){

}'

I think now that main is out of the way it wants me to string the upload path, but I don't know if I'm meeting the parameter requirement, since I still keep getting this error like my previous post:

Screenshot.java:16: ';' expected

boolean captureScreenShot(String uploadPath)

The String: uploadPath looks like it should contain the path to the folder where you want the captured file written. Look at the API doc for the write() method of the ImageIO class and at the API doc for the File class.

I was on oracle just now, confusing. This is too new and I'm trying to get this done quick.

Is there any place that gives verbose code examples? I'm seeing nested methods without it being explained by workable example.

I need a quick hand holding primer and then I pretty much got it, I just don't have time for pure manual stuff atm. Time not my friend.

and I'm grateful for the help so far, not a spoiled newb. I'm proficient in a couple server side languages

:'(

You still need to post your new code base.

same error going on, idk how to satisfy the uploadPath param. I'm just not getting the manual defs without code example.

Screenshot.java:16: ';' expected

boolean captureScreenShot(String uploadPath)

and the source..

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ScreenShot {
/**
method to capture screen shot
@param String uploadPath to save screen shot as image
@returns boolean true if capture successful else false
*/
public static void main(String [] args){
boolean captureScreenShot(String uploadPath) 
{
boolean isSuccesful = false;
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture;
try {
capture = new Robot().createScreenCapture(screenRect);
// screen shot image will be save at given path with name "screen.jpeg"
ImageIO.write(capture, "jpg", new File(uploadPath, "screen.jpeg")); 
isSuccesful = true;
} catch (AWTException awte) {
awte.printStackTrace();
isSuccesful = false;
}
catch (IOException ioe) {
ioe.printStackTrace();
isSuccesful = false;
}
return isSuccesful;
}
}
}

you can't create a method inside main instead you should create an instance of the public class in the main method then call the class' method

well ... instantiating might not be necessary, but you can't create a method within a method.

can somebody here with java try this with a working example. I'd love to just see this actually do the screengrab at this point.

I probably won't be able to understand what liken just said for a week unfortunately.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.