• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating an instance of a class in another class

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic