• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot) Exception

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I've write the code to take the screenshots :

package screenshot;

import java.applet.Applet;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import javax.imageio.ImageIO;
import java.util.*;

public class TakeSnap extends Applet {
public void paint (Graphics g) {

SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHs");
Date d = new Date();
String dateNow = sd.format(d);
g.drawString("Hi My Boss created me: "+dateNow, 50,50);
AWTPermission per = new AWTPermission( "createRobot" );

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
try{

Robot robot = new Robot();


while(true){
d = new Date();
dateNow = sd.format(d);
Thread.sleep(2000);
BufferedImage image = robot.createScreenCapture(rectangle);
File file=new File("d:\\sc\\sc"+dateNow+".jpg");
ImageIO.write(image,"jpg", file);

}
}catch(Exception e){
e.printStackTrace();
}
}
}


the above code is gets executed from netbeans(right click and run ) but from the command prompt it is giving the following error.


java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.awt.Robot.checkRobotAllowed(Robot.java:126)
at java.awt.Robot.init(Robot.java:114)
at java.awt.Robot.<init>(Robot.java:76)
at screenshot.TakeSnap.paint(TakeSnap.java:33)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
at java.awt.Component.dispatchEventImpl(Component.java:4486)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

please help me
-------
Thank in advance
Madhu
 
Madhu Menda
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Madhu Menda wrote: Hi All,

I've write the code to take the screenshots :

package screenshot;

import java.applet.Applet;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import javax.imageio.ImageIO;
import java.util.*;

public class TakeSnap extends Applet {
public void paint (Graphics g) {

SimpleDateFormat sd = new SimpleDateFormat("yyyyMMddHs");
Date d = new Date();
String dateNow = sd.format(d);
g.drawString("Hi My Boss created me: "+dateNow, 50,50);
AWTPermission per = new AWTPermission( "createRobot" );

Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
try{

Robot robot = new Robot();


while(true){
d = new Date();
dateNow = sd.format(d);
Thread.sleep(2000);
BufferedImage image = robot.createScreenCapture(rectangle);
File file=new File("d:\\sc\\sc"+dateNow+".jpg");
ImageIO.write(image,"jpg", file);

}
}catch(Exception e){
e.printStackTrace();
}
}
}


the above code is gets executed from netbeans(right click and run ) but from the command prompt it is giving the following error.


java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:323)
at java.security.AccessController.checkPermission(AccessController.java:
546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.awt.Robot.checkRobotAllowed(Robot.java:126)
at java.awt.Robot.init(Robot.java:114)
at java.awt.Robot.<init>(Robot.java:76)
at screenshot.TakeSnap.paint(TakeSnap.java:33)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
at java.awt.Component.dispatchEventImpl(Component.java:4486)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

please help me
-------
Thank in advance
Madhu




Hi all i added the following entries in java.policy file

permission java.awt.AWTPermission "createRobot";
permission java.awt.AWTPermission "accessClipboard";
permission java.awt.AWTPermission "accessEventQueue";
permission java.awt.AWTPermission "showWindowWithoutWarningBanner";
permission java.awt.AWTPermission "readDisplayPixels", "read";

permission java.io.FilePermission "<<ALL FILES>>", "read, write, delete, execute";


the problem got solved....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic