File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes java.lang.reflect.InvocationTargetException while loading a signed jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "java.lang.reflect.InvocationTargetException while loading a signed jar" Watch "java.lang.reflect.InvocationTargetException while loading a signed jar" New topic

java.lang.reflect.InvocationTargetException while loading a signed jar

Srikanth Paladugu

Joined: Mar 17, 2013
Posts: 2
I am trying to take a screenshot of the desktop and upload/save it somewhere. Sample code looks like this. The java file is
public class ScreenShot extends Applet
ScreenShotThread t = new ScreenShotThread();
public void init()

public boolean mouseDown(Event e,int x, int y)
return true;

The thread class looks like this:
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

public class ScreenShotThread extends Thread
String request = "xxxx";
public void run()
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
Robot screenshot = new Robot();
BufferedImage screenImage = screenshot.createScreenCapture(new
sendBufferedImage(request, screenImage);
catch (Exception e)

public void sendBufferedImage(String urlpath, BufferedImage screenImage) throws
URL url = new URL(urlpath);
URLConnection urlcon = url.openConnection();
OutputStream out = urlcon.getOutputStream();
ImageIO.write(screenImage, "jpg", out);

Out of these, I have created a jar file which consists of only one class file, that of the applet i.e, "ScreenShot". I have signed the jar file and included it in a HTML for invoking like this

<applet code="ScreenShot.class" archive="ScreenShot.jar"/>

When I run the html, I get the security warnings, and once I accept to the risk, I get this error. "java.lang.reflect.InvocationTargetException". What I observed is, this error is not originating from within the code I have written, since I could not see any SOPs I used in the above files on the java console.
The interesting part is, if I didn't sign my applet, then I get a security exception at initialization of the robot class in the ScreenShotThread class.

Appreciate any help.

James Boswell

Joined: Nov 09, 2011
Posts: 1051

An InvocationTargetException usually wraps the underlying problem. Can you post the full stacktrace?
I agree. Here's the link:
subject: java.lang.reflect.InvocationTargetException while loading a signed jar
It's not a secret anymore!