(这是在做老师要求交的一个大作业中遇到的)在Main类中调用同一个包中的Login类,出错提示如下,百度过好像是API的什么安全问题,但弄不懂,请各位大神帮帮忙 %>_<%
提示错误:
Running with locale: Chinese (Simplified)_People's Republic of China.936
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.midlet.MIDletState.<init>(+83)
at javax.microedition.midlet.MIDletProxy.<init>(+5)
at javax.microedition.midlet.MIDlet.<init>(+13)
at Login.<init>(+4)
at Main.commandAction(+15)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+194)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+51)
main类中的代码:import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Main extends MIDlet implements CommandListener {
private Display display;
private TextBox textBox;
private Command loginCommand;
private Command orderCommand;
private Command submitCommand;
private Command saveCommand;
private Command undoCommand;
private Command exitCommand;
private Command backCommand;
public Main() {
display = Display.getDisplay(this);
textBox = new TextBox("手机点餐系统 V1.0","欢迎使用手机点餐系统,很高兴能为您服务!",50,0); loginCommand = new Command("登陆",Command.SCREEN,1);
orderCommand = new Command("点餐",Command.SCREEN,1);
submitCommand = new Command("提交订单",Command.SCREEN,1);
saveCommand = new Command("订单状态查询",Command.SCREEN,1);
undoCommand = new Command("撤销订单",Command.SCREEN,1);
exitCommand = new Command("退出",Command.SCREEN,1);
backCommand = new Command("返回",Command.BACK,2);
textBox.addCommand(loginCommand);
textBox.addCommand(orderCommand);
textBox.addCommand(submitCommand);
textBox.addCommand(saveCommand);
textBox.addCommand(undoCommand);
textBox.addCommand(exitCommand);
textBox.addCommand(backCommand);
} public void startApp() {
textBox.setCommandListener(this);
display.setCurrent(textBox);
} public void pauseApp() {
} public void destroyApp(boolean uncondition) {
} public void commandAction(Command c, Displayable s) {
if(c == loginCommand) {
Login login= new Login();
login.startApp();
textBox.setString("登陆命令被执行");
}
if(c == orderCommand) {
textBox.setString("点餐命令被执行");
}
if(c == submitCommand) {
textBox.setString("提交命令被执行");
}
if(c == saveCommand) {
textBox.setString("查询命令被执行");
}
if(c == undoCommand) {
textBox.setString("撤销命令被执行");
}
if(c == backCommand) {
// textBox.setString("返回命令被执行");
}
if(c == exitCommand) {
textBox.setString("退出命令被执行");
destroyApp(false);
notifyDestroyed();
}
}
}
提示错误:
Running with locale: Chinese (Simplified)_People's Republic of China.936
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.midlet.MIDletState.<init>(+83)
at javax.microedition.midlet.MIDletProxy.<init>(+5)
at javax.microedition.midlet.MIDlet.<init>(+13)
at Login.<init>(+4)
at Main.commandAction(+15)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+194)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+51)
main类中的代码:import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Main extends MIDlet implements CommandListener {
private Display display;
private TextBox textBox;
private Command loginCommand;
private Command orderCommand;
private Command submitCommand;
private Command saveCommand;
private Command undoCommand;
private Command exitCommand;
private Command backCommand;
public Main() {
display = Display.getDisplay(this);
textBox = new TextBox("手机点餐系统 V1.0","欢迎使用手机点餐系统,很高兴能为您服务!",50,0); loginCommand = new Command("登陆",Command.SCREEN,1);
orderCommand = new Command("点餐",Command.SCREEN,1);
submitCommand = new Command("提交订单",Command.SCREEN,1);
saveCommand = new Command("订单状态查询",Command.SCREEN,1);
undoCommand = new Command("撤销订单",Command.SCREEN,1);
exitCommand = new Command("退出",Command.SCREEN,1);
backCommand = new Command("返回",Command.BACK,2);
textBox.addCommand(loginCommand);
textBox.addCommand(orderCommand);
textBox.addCommand(submitCommand);
textBox.addCommand(saveCommand);
textBox.addCommand(undoCommand);
textBox.addCommand(exitCommand);
textBox.addCommand(backCommand);
} public void startApp() {
textBox.setCommandListener(this);
display.setCurrent(textBox);
} public void pauseApp() {
} public void destroyApp(boolean uncondition) {
} public void commandAction(Command c, Displayable s) {
if(c == loginCommand) {
Login login= new Login();
login.startApp();
textBox.setString("登陆命令被执行");
}
if(c == orderCommand) {
textBox.setString("点餐命令被执行");
}
if(c == submitCommand) {
textBox.setString("提交命令被执行");
}
if(c == saveCommand) {
textBox.setString("查询命令被执行");
}
if(c == undoCommand) {
textBox.setString("撤销命令被执行");
}
if(c == backCommand) {
// textBox.setString("返回命令被执行");
}
if(c == exitCommand) {
textBox.setString("退出命令被执行");
destroyApp(false);
notifyDestroyed();
}
}
}
MIDlet的实例化必须由系统来操作