Forums Register Login

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

+Pie Number of slices to send: Send
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()
{
t.start();
}

public boolean mouseDown(Event e,int x, int y)
{
t.stop();
return true;
}
}
**************************

The thread class looks like this:
*************************
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.imageio.ImageIO;

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

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

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

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

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.

Thanks
S
+Pie Number of slices to send: Send
An InvocationTargetException usually wraps the underlying problem. Can you post the full stacktrace?
Just the other day, I was thinking ... about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2271 times.
Similar Threads
Applet(with images) running problem at Client
how to deploy a Swing Applet that accesses the System Clipboard
how to implement the processing of events without creating a window
java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot) Exception
Robot().createScreenCapture() to capture 2nd monitor?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:40:42.