日期:2014-05-20  浏览次数:20854 次

java.lang.SecurityException: Application not authorized to access the restricted API问题,急急急!!
Layertest.java文件代码:
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class Layertest extends MIDlet {
  MyCanvas m;
  Display dis;
public Layertest() {
// TODO Auto-generated constructor stub
// super();
dis=Display.getDisplay(this);
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub

}

protected void pauseApp() {
// TODO Auto-generated method stub

}

protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
m=new MyCanvas(dis);
  dis.setCurrent(m);
}

}

MyCanvas.java文件代码:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

public class MyCanvas extends GameCanvas implements Runnable {

Image img;
Graphics g;
Display dis;
// private TiledLayer backLayer;
// private static int map[]={1,1,3,5,5,6,6,7,7};
public MyCanvas(Display dis) {
super(true);
g=getGraphics();
try
{
img=Image.createImage("/8.jpg");
}
catch(Exception e)
{}
/* backLayer=new TiledLayer(9,1,img,3,3);
for(int i=0;i<map.length;i++)
{
backLayer.setCell(i, 0, map[i]);
}*/
// draw();
new Thread(this).start();
// TODO Auto-generated constructor stub
}
public void draw()
{
// g.setColor(0x000000);
// g.drawImage(img, 0, 0, Graphics.TOP|Graphics.LEFT);
// backLayer.paint(g);
// flushGraphics();
}
public void run() {
// TODO Auto-generated method stub
while(true)
{
draw();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
运行Layertest.java,手机屏闪一下消失,然后报以下错误
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\MediaControlSkin
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
java.lang.SecurityException: Application not authorized to access the restricted API
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(+40)
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(+7)
at com.sun.midp.midletsuite.MIDletSuiteImpl.checkIfPermissionAllowed(+8)
at com.sun.midp.midletsuite.Installer.getInstaller(+18)
at com.sun.midp.dev.Manager.<init>(+298)
at java.lang.Class.runCustomCode(+0)
at com.sun.midp.midlet.MIDletState.createMIDlet(+34)
at com.sun.midp.midlet.Scheduler.schedule(+52)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)
Execution completed.
3385989 bytecodes executed
16 thread switches
1666 classes in the system (including system classes)
17560 dynamic objects allocated (524204 bytes)
1 garbage collections (0 bytes collected)


------解决方案--------------------
不允许访问受限制的API
------解决方案--------------------
恩大概安全访问限制