Skip to main content

java.lang.SecurityException

1 reply [Last post]
sarathgopalr
Offline
Joined: 2007-07-26

I tried the following code to open a new form but it produces error:

java.lang.SecurityException: Application not authorized to access the restricted API
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(SecurityToken.java:170)
at com.sun.midp.security.SecurityToken.checkIfPermissionAllowed(SecurityToken.java:145)
at com.sun.midp.midletsuite.MIDletSuiteImpl.checkIfPermissionAllowed(+8)
at com.sun.midp.midlet.MIDletState.(+83)
at javax.microedition.midlet.MIDletProxy.(MIDletProxy.java:33)
at javax.microedition.midlet.MIDlet.(MIDlet.java:70)
at FaceMid.(FaceMid.java:24)
at Message.(Message.java:20)
at FaceMid.actionPerformed(FaceMid.java:68)
at com.sun.lwuit.util.EventDispatcher.fireActionSync(EventDispatcher.java:252)
at com.sun.lwuit.util.EventDispatcher.fireActionEvent(EventDispatcher.java:211)
at com.sun.lwuit.Button.fireActionEvent(Button.java:253)
at com.sun.lwuit.Button.released(Button.java:274)
at com.sun.lwuit.Button.keyReleased(Button.java:292)
at com.sun.lwuit.Form.keyReleased(Form.java:1441)
at com.sun.lwuit.Display.handleEvent(Display.java:1125)
at com.sun.lwuit.Display.edtLoopImpl(Display.java:583)
at com.sun.lwuit.Display.mainEDTLoop(Display.java:541)
at com.sun.lwuit.Display$1.run(Display.java:278)

There are two classes FaceMid.java and Message.java
The code for FaceMid which is the main class is as follows

import com.sun.lwuit.Button;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.GridLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import javax.microedition.midlet.*;

public class FaceMid extends MIDlet implements ActionListener{
Form f;

Button Msg;
public FaceMid(){
try {
Resources r = Resources.open("/businessTheme.res");
UIManager.getInstance().setThemeProps(r.getTheme("businessTheme"));
} catch (Exception ioe) {
System.out.println("Couldn't load theme.");

}

Display.init(this);
f=new Form();
// setMainForm();
f.setLayout(new GridLayout(4,4));
Msg=new Button("Message");
Msg.addActionListener(this);
f.addComponent(Msg);
}

public void startApp() {
f.show();

}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
void setMainForm(){

f.setLayout(new GridLayout(4,4));
Msg=new Button("Message");
Msg.addActionListener(this);
f.addComponent(Msg);

}

public void actionPerformed(ActionEvent ae) {

if(ae.getSource().equals(Msg)){
// Message m=
new Message();
}

}
}
/////////////////////////////////////////////END OF FaceMid.java///////////////////////////////
and of Message.java is as follows:

import com.sun.lwuit.Button;
import com.sun.lwuit.Form;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;

public class Message extends FaceMid{
Form msgf;
Button send;

public Message(){

msgf=new Form("Message");

send=new Button("Send");
msgf.addComponent(send);
msgf.show();
}

}
///////////////////////////END OF Message.java////////////////////////////////////////////////////
iam confused why a security exception is shown as above...can anybody tell me why this error appears..???

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kawaiimomo
Offline
Joined: 2008-07-10

you should call Display.init() before loading the resources.