Hello,
I am writing a Java applet which uses the JExcel API to write to an Excel file. I have pasted the run-time error that I get below. After some research about the Exception, I added a policy entry using the policytool command for any Java program by selecting CodeBase<ALL>. That did not work. I would be appreciate any help on how to fix this issue. All my program files and the "file.xls" is stored in the same folder.
Thank you!
import javax.swing.*;
import java.awt.Graphics;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.util.Scanner;
import java.text.DecimalFormat;
import java.awt.Color;
import java.io.IOException;
import java.io.FileWriter;
import java.text.DecimalFormat;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.LineNumberReader;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import jxl.write.Number;
import jxl.write.*;
import jxl.read.biff.BiffException;
import jxl.Workbook;
public class GUI extends JApplet
{
private WritableWorkbook workbook;
private WritableSheet sheet[] = new WritableSheet[10];
public void init()
{
initializeSheets();
setVisible (true);
setSize (500, 500);
}
public void initializeSheets()
{
try {
String fileName = "file.xls";
try{
workbook = Workbook.createWorkbook(new File(fileName));
}
catch (IOException e){}
catch (ExceptionInInitializerError er){}
for(int i = 0; i < 10; i++)
{
workbook.createSheet("Sheet" + i , i);
WritableSheet sheet = workbook.getSheet(i);
}
Number n = new Number(0,0,0);
Number num = new Number(0,0,1);
sheet[0].addCell(n);
sheet[1].addCell(num);
try{
workbook.write();
workbook.close();
}
catch (IOException e){}
}
catch (WriteException e) { }
setSize(500,500);
setVisible (true);
}
}
java.security.AccessControlException: access denied ("java.io.FilePermission" "
:\Users\sridhar\Desktop\jexcelapi\jxl.jar" "read")
at java.security.AccessControlContext.checkPermission(AccessControlCont
t.java:366)
at java.security.AccessController.checkPermission(AccessController.java
55)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.net.URLClassLoader$4.run(URLClassLoader.java:690)
at java.net.URLClassLoader$4.run(URLClassLoader.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.getPermissions(URLClassLoader.java:688)
at sun.applet.AppletClassLoader.getPermissions(AppletClassLoader.java:2
)
at java.security.SecureClassLoader.getProtectionDomain(SecureClassLoade
java:206)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:1
)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:180)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404)
at java.lang.Class.getConstructor0(Class.java:2714)
at java.lang.Class.newInstance0(Class.java:343)
at java.lang.Class.newInstance(Class.java:325)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:795)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:724)
at sun.applet.AppletPanel.run(AppletPanel.java:378)
at java.lang.Thread.run(Thread.java:722)