• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating an instance of a class in another class

 
Jack Davis
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'n trying to organise my midlets in a mainatinable way, so I'm creating several classes. However I'm having trouble referncing between classes. For example creating an instance of a class in another class gives me the following error......

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>(+66)
at javax.microedition.midlet.MIDletProxy.<init>(+5)
at javax.microedition.midlet.MIDlet.<init>(+13)
at subscribe.<init>(+4)
at Traffic.commandAction(+38)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+284)
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.run(+250)
Any help would be appreciated. Thanks
 
Carlos Quiroz
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
So you are calling in one class new ClassName() and get that exception? That is very strange.
What kind of class are you trying to instantiate? Perhaps you gave the class a forbidden package name like javax.microedition.XXX?
Regards
 
David Price
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the stack trace, it seems like his method commandAction in class Traffic is trying to create a new instance of class 'subscribe', which extends MIDlet.
In general, you may not create instances of classes extending MIDlet: that's the job of the phone's Java VM (actually, its application manager). If you try, you'll correctly get a security exception.
Since this MIDlet subclass called 'subscribe' is not actually being used here as a MIDlet (i.e. a thing the user can run, managed by the application manager), move the functionality needed from it here into a separate non-MIDlet class, then create an instance of that instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic