Sercurity Settings.

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2008
Posts: 25
Reputation: Dancealot is an unknown quantity at this point 
Solved Threads: 0
Dancealot Dancealot is offline Offline
Light Poster

Sercurity Settings.

 
0
  #1
Aug 26th, 2008
Hi all.
Thanks for a very nice board.
I have come across a problem when i create a midlet. The midlet functions as a normal menu system, and have to call different methods, to start or stop a bluetooth server and client. I have gotten the code for the server and client from another website, but when I try to open the midlet, I get the following 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.<init>(+83)
at javax.microedition.midlet.MIDletProxy.<init>(MIDletProxy.java:33)
at javax.microedition.midlet.MIDlet.<init>(MIDlet.java:70)
at bluechew.BlueChewMIDlet.<init>(BlueChewMIDlet.java:12)
at bluechew.VisualMIDlet.getWelcome(VisualMIDlet.java:182)
at bluechew.VisualMIDlet.startMIDlet(VisualMIDlet.java:67)
at bluechew.VisualMIDlet.startApp(VisualMIDlet.java:504)
at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:44)
at com.sun.midp.midlet.Scheduler.schedule(+270)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)


  1.  
  2. package bluechew;
  3.  
  4. /*
  5.  * To change this template, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9.  
  10. import javax.microedition.midlet.*;
  11. import javax.microedition.lcdui.*;
  12. import org.netbeans.microedition.lcdui.SplashScreen;
  13. import org.netbeans.microedition.lcdui.WaitScreen;
  14. import org.netbeans.microedition.util.SimpleCancellableTask;
  15.  
  16. /**
  17.  * @author MMA
  18.  */
  19. public class VisualMIDlet extends MIDlet implements CommandListener {
  20. private my_finder finder;
  21. private BlueChewServer server;
  22. private boolean midletPaused = false;
  23.  
  24. //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">
  25. private SplashScreen welcome;
  26. private List Menu;
  27. private WaitScreen open_client;
  28. private WaitScreen open_server;
  29. private WaitScreen close_client;
  30. private WaitScreen close_server;
  31. private SimpleCancellableTask task;
  32. private SimpleCancellableTask task1;
  33. private SimpleCancellableTask task2;
  34. private Image image1;
  35. private Image image2;
  36. private SimpleCancellableTask task3;
  37. private SimpleCancellableTask task4;
  38. private SimpleCancellableTask task5;
  39. //</editor-fold>
  40.  
  41. /**
  42.   * The VisualMIDlet constructor.
  43.   */
  44. public VisualMIDlet() {
  45. }
  46.  
  47. //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">
  48. //</editor-fold>
  49.  
  50. //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">
  51. /**
  52.  * Initilizes the application.
  53.  * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
  54.  */
  55. private void initialize () {
  56. // write pre-initialize user code here
  57.  
  58. // write post-initialize user code here
  59. }
  60. //</editor-fold>
  61.  
  62. //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">
  63. /**
  64.  * Performs an action assigned to the Mobile Device - MIDlet Started point.
  65.  */
  66. public void startMIDlet () {
  67. // write pre-action user code here
  68. switchDisplayable (null, getWelcome ());
  69. // write post-action user code here
  70. }
  71. //</editor-fold>
  72.  
  73. //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">
  74. /**
  75.  * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
  76.  */
  77. public void resumeMIDlet () {
  78. // write pre-action user code here
  79.  
  80. // write post-action user code here
  81. }
  82. //</editor-fold>
  83.  
  84. //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">
  85. /**
  86.  * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
  87.  * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
  88.  * @param nextDisplayable the Displayable to be set
  89.  */
  90. public void switchDisplayable (Alert alert, Displayable nextDisplayable) {
  91. // write pre-switch user code here
  92. Display display = getDisplay ();
  93. if (alert == null) {
  94. display.setCurrent (nextDisplayable);
  95. } else {
  96. display.setCurrent (alert, nextDisplayable);
  97. }
  98. // write post-switch user code here
  99. }
  100. //</editor-fold>
  101.  
  102. //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">
  103. /**
  104.  * Called by a system to indicated that a command has been invoked on a particular displayable.
  105.  * @param command the Command that was invoked
  106.  * @param displayable the Displayable where the command was invoked
  107.  */
  108. public void commandAction (Command command, Displayable displayable) {
  109. // write pre-action user code here
  110. if (displayable == Menu) {
  111. if (command == List.SELECT_COMMAND) {
  112. // write pre-action user code here
  113. MenuAction ();
  114. // write post-action user code here
  115. }
  116. } else if (displayable == close_client) {
  117. if (command == WaitScreen.FAILURE_COMMAND) {
  118. // write pre-action user code here
  119.  
  120. // write post-action user code here
  121. } else if (command == WaitScreen.SUCCESS_COMMAND) {
  122. // write pre-action user code here
  123.  
  124. // write post-action user code here
  125. }
  126. } else if (displayable == close_server) {
  127. if (command == WaitScreen.FAILURE_COMMAND) {
  128. // write pre-action user code here
  129.  
  130. // write post-action user code here
  131. } else if (command == WaitScreen.SUCCESS_COMMAND) {
  132. // write pre-action user code here
  133.  
  134. // write post-action user code here
  135. }
  136. } else if (displayable == open_client) {
  137. if (command == WaitScreen.FAILURE_COMMAND) {
  138. // write pre-action user code here
  139.  
  140. // write post-action user code here
  141. } else if (command == WaitScreen.SUCCESS_COMMAND) {
  142. // write pre-action user code here
  143.  
  144. // write post-action user code here
  145. }
  146. } else if (displayable == open_server) {
  147. if (command == WaitScreen.FAILURE_COMMAND) {
  148. // write pre-action user code here
  149.  
  150. // write post-action user code here
  151. } else if (command == WaitScreen.SUCCESS_COMMAND) {
  152. // write pre-action user code here
  153.  
  154. // write post-action user code here
  155. }
  156. } else if (displayable == welcome) {
  157. if (command == SplashScreen.DISMISS_COMMAND) {
  158. // write pre-action user code here
  159. switchDisplayable (null, getMenu ());
  160. // write post-action user code here
  161. }
  162. }
  163. // write post-action user code here
  164. }
  165. //</editor-fold>
  166.  
  167. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: welcome ">
  168. /**
  169.  * Returns an initiliazed instance of welcome component.
  170.  * @return the initialized component instance
  171.  */
  172. public SplashScreen getWelcome () {
  173. if (welcome == null) {
  174. // write pre-init user code here
  175. welcome = new SplashScreen (getDisplay ());
  176. welcome.setTitle ("splashScreen");
  177. welcome.setCommandListener (this);
  178. welcome.setImage (getImage2 ());
  179. welcome.setText ("hearing aid control application");
  180. welcome.setTimeout (2000);
  181. // write post-init user code here
  182.  
  183. bluechew.BlueChewMIDlet mbluechewmidlet = new bluechew.BlueChewMIDlet();
  184. mbluechewmidlet.startApp();
  185.  
  186. }
  187. return welcome;
  188. }
  189. //</editor-fold>
  190.  
  191. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task ">
  192. /**
  193.  * Returns an initiliazed instance of task component.
  194.  * @return the initialized component instance
  195.  */
  196. public SimpleCancellableTask getTask () {
  197. if (task == null) {
  198. // write pre-init user code here
  199. task = new SimpleCancellableTask ();
  200. task.setExecutable (new org.netbeans.microedition.util.Executable() {
  201. public void execute () throws Exception {
  202. // write task-execution user code here
  203. }
  204. });
  205. // write post-init user code here
  206. }
  207. return task;
  208. }
  209. //</editor-fold>
  210.  
  211. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Menu ">
  212. /**
  213.  * Returns an initiliazed instance of Menu component.
  214.  * @return the initialized component instance
  215.  */
  216. public List getMenu () {
  217. if (Menu == null) {
  218. // write pre-init user code here
  219. Menu = new List ("list", Choice.IMPLICIT);
  220. Menu.append ("Open Server", null);
  221. Menu.append ("Open Client", null);
  222. Menu.append ("Close Server", null);
  223. Menu.append ("Close Client", null);
  224. Menu.setCommandListener (this);
  225. Menu.setSelectedFlags (new boolean[] { false, false, false, false });
  226. // write post-init user code here
  227. }
  228. return Menu;
  229. }
  230. //</editor-fold>
  231.  
  232. //<editor-fold defaultstate="collapsed" desc=" Generated Method: MenuAction ">
  233. /**
  234.  * Performs an action assigned to the selected list element in the Menu component.
  235.  */
  236. public void MenuAction () {
  237. // enter pre-action user code here
  238. String __selectedString = getMenu ().getString (getMenu ().getSelectedIndex ());
  239. if (__selectedString != null) {
  240. if (__selectedString.equals ("Open Server")) {
  241. // write pre-action user code here
  242. switchDisplayable (null, getOpen_server ());
  243. // write post-action user code here
  244. } else if (__selectedString.equals ("Open Client")) {
  245. // write pre-action user code here
  246. switchDisplayable (null, getOpen_client ());
  247. // write post-action user code here
  248. } else if (__selectedString.equals ("Close Server")) {
  249. // write pre-action user code here
  250. switchDisplayable (null, getClose_server ());
  251. // write post-action user code here
  252. } else if (__selectedString.equals ("Close Client")) {
  253. // write pre-action user code here
  254. switchDisplayable (null, getClose_client ());
  255. // write post-action user code here
  256. }
  257. }
  258. // enter post-action user code here
  259. }
  260. //</editor-fold>
  261.  
  262. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: open_client ">
  263. /**
  264.  * Returns an initiliazed instance of open_client component.
  265.  * @return the initialized component instance
  266.  */
  267. public WaitScreen getOpen_client () {
  268. if (open_client == null) {
  269. // write pre-init user code here
  270. open_client = new WaitScreen (getDisplay ());
  271. open_client.setTitle ("Open Client ");
  272. open_client.setCommandListener (this);
  273. open_client.setImage (getImage1 ());
  274. open_client.setText ("Client connection Opening");
  275. open_client.setTask (getTask2 ());
  276. // write post-init user code here
  277. }
  278. return open_client;
  279. }
  280. //</editor-fold>
  281.  
  282. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task1 ">
  283. /**
  284.  * Returns an initiliazed instance of task1 component.
  285.  * @return the initialized component instance
  286.  */
  287. public SimpleCancellableTask getTask1 () {
  288. if (task1 == null) {
  289. // write pre-init user code here
  290. task1 = new SimpleCancellableTask ();
  291. task1.setExecutable (new org.netbeans.microedition.util.Executable() {
  292. public void execute () throws Exception {
  293. // write task-execution user code here
  294. }
  295. });
  296. // write post-init user code here
  297. }
  298. return task1;
  299. }
  300. //</editor-fold>
  301.  
  302. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task2 ">
  303. /**
  304.  * Returns an initiliazed instance of task2 component.
  305.  * @return the initialized component instance
  306.  */
  307. public SimpleCancellableTask getTask2 () {
  308. if (task2 == null) {
  309. // write pre-init user code here
  310. task2 = new SimpleCancellableTask ();
  311. task2.setExecutable (new org.netbeans.microedition.util.Executable() {
  312. public void execute () throws Exception {
  313. // write task-execution user code here
  314. finder.start();
  315. }
  316. });
  317. // write post-init user code here
  318. }
  319. return task2;
  320. }
  321. //</editor-fold>
  322.  
  323. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image1 ">
  324. /**
  325.  * Returns an initiliazed instance of image1 component.
  326.  * @return the initialized component instance
  327.  */
  328. public Image getImage1 () {
  329. if (image1 == null) {
  330. // write pre-init user code here
  331. try {
  332. image1 = Image.createImage ("/bluetooth_small.jpg");
  333. } catch (java.io.IOException e) {
  334. e.printStackTrace ();
  335. }
  336. // write post-init user code here
  337. }
  338. return image1;
  339. }
  340. //</editor-fold>
  341.  
  342. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image2 ">
  343. /**
  344.  * Returns an initiliazed instance of image2 component.
  345.  * @return the initialized component instance
  346.  */
  347. public Image getImage2 () {
  348. if (image2 == null) {
  349. // write pre-init user code here
  350. try {
  351. image2 = Image.createImage ("/HighDifinitionHearing.gif");
  352. } catch (java.io.IOException e) {
  353. e.printStackTrace ();
  354. }
  355. // write post-init user code here
  356. }
  357. return image2;
  358. }
  359. //</editor-fold>
  360.  
  361. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: open_server ">
  362. /**
  363.  * Returns an initiliazed instance of open_server component.
  364.  * @return the initialized component instance
  365.  */
  366. public WaitScreen getOpen_server () {
  367. if (open_server == null) {
  368. // write pre-init user code here
  369. open_server = new WaitScreen (getDisplay ());
  370. open_server.setTitle ("waitScreen");
  371. open_server.setCommandListener (this);
  372. open_server.setTask (getTask3 ());
  373. // write post-init user code here
  374. }
  375. return open_server;
  376. }
  377. //</editor-fold>
  378.  
  379. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: close_client ">
  380. /**
  381.  * Returns an initiliazed instance of close_client component.
  382.  * @return the initialized component instance
  383.  */
  384. public WaitScreen getClose_client () {
  385. if (close_client == null) {
  386. // write pre-init user code here
  387. close_client = new WaitScreen (getDisplay ());
  388. close_client.setTitle ("waitScreen");
  389. close_client.setCommandListener (this);
  390. close_client.setTask (getTask4 ());
  391. // write post-init user code here
  392. }
  393. return close_client;
  394. }
  395. //</editor-fold>
  396.  
  397. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: close_server ">
  398. /**
  399.  * Returns an initiliazed instance of close_server component.
  400.  * @return the initialized component instance
  401.  */
  402. public WaitScreen getClose_server () {
  403. if (close_server == null) {
  404. // write pre-init user code here
  405. close_server = new WaitScreen (getDisplay ());
  406. close_server.setTitle ("waitScreen");
  407. close_server.setCommandListener (this);
  408. close_server.setTask (getTask5 ());
  409. // write post-init user code here
  410. }
  411. return close_server;
  412. }
  413. //</editor-fold>
  414.  
  415. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task3 ">
  416. /**
  417.  * Returns an initiliazed instance of task3 component.
  418.  * @return the initialized component instance
  419.  */
  420. public SimpleCancellableTask getTask3 () {
  421. if (task3 == null) {
  422. // write pre-init user code here
  423. task3 = new SimpleCancellableTask ();
  424. task3.setExecutable (new org.netbeans.microedition.util.Executable() {
  425. public void execute () throws Exception {
  426. // write task-execution user code here
  427. server.start();
  428. }
  429. });
  430. // write post-init user code here
  431. }
  432. return task3;
  433. }
  434. //</editor-fold>
  435.  
  436. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task4 ">
  437. /**
  438.  * Returns an initiliazed instance of task4 component.
  439.  * @return the initialized component instance
  440.  */
  441. public SimpleCancellableTask getTask4 () {
  442. if (task4 == null) {
  443. // write pre-init user code here
  444. task4 = new SimpleCancellableTask ();
  445. task4.setExecutable (new org.netbeans.microedition.util.Executable() {
  446. public void execute () throws Exception {
  447. // write task-execution user code here
  448.  
  449. finder.stop();
  450. }
  451. });
  452. // write post-init user code here
  453. }
  454. return task4;
  455. }
  456. //</editor-fold>
  457.  
  458. //<editor-fold defaultstate="collapsed" desc=" Generated Getter: task5 ">
  459. /**
  460.  * Returns an initiliazed instance of task5 component.
  461.  * @return the initialized component instance
  462.  */
  463. public SimpleCancellableTask getTask5 () {
  464. if (task5 == null) {
  465. // write pre-init user code here
  466. task5 = new SimpleCancellableTask ();
  467. task5.setExecutable (new org.netbeans.microedition.util.Executable() {
  468. public void execute () throws Exception {
  469. // write task-execution user code here
  470. server.stop();
  471. }
  472. });
  473. // write post-init user code here
  474. }
  475. return task5;
  476. }
  477. //</editor-fold>
  478.  
  479. /**
  480.   * Returns a display instance.
  481.   * @return the display instance.
  482.   */
  483. public Display getDisplay () {
  484. return Display.getDisplay(this);
  485. }
  486.  
  487. /**
  488.   * Exits MIDlet.
  489.   */
  490. public void exitMIDlet() {
  491. switchDisplayable (null, null);
  492. destroyApp(true);
  493. notifyDestroyed();
  494. }
  495.  
  496. /**
  497.   * Called when MIDlet is started.
  498.   * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
  499.   */
  500. public void startApp() {
  501. if (midletPaused) {
  502. resumeMIDlet ();
  503. } else {
  504. initialize ();
  505. startMIDlet ();
  506. }
  507. midletPaused = false;
  508. }
  509.  
  510. /**
  511.   * Called when MIDlet is paused.
  512.   */
  513. public void pauseApp() {
  514. midletPaused = true;
  515. }
  516.  
  517. /**
  518.   * Called to signal the MIDlet to terminate.
  519.   * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
  520.   */
  521. public void destroyApp(boolean unconditional) {
  522. }
  523.  
  524. }

Hope you can help me. thanks in advance.
Michael Madsen.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,267
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Sercurity Settings.

 
-1
  #2
Aug 26th, 2008
Can you attach either copy of src folder or whole project as I'm not sure what changes you made to BlueChewServer. Plus you calling some "my_finder" which seems to be product of yours (if it is name of class you should get slap on hand as this is not correct way to name a class, it should be MyFinder)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 25
Reputation: Dancealot is an unknown quantity at this point 
Solved Threads: 0
Dancealot Dancealot is offline Offline
Light Poster

Re: Sercurity Settings.

 
0
  #3
Aug 27th, 2008
Hi Peter.

Here is an attacthment of the source. I havent changed anything in the server, så this is just an implementation of a midlet, as a replacement of the midlet that was already made. The my_finder, is just my try of making an instance of the midlet. I dont know if that was the correct way to do it. thanks in advance. Michael Madsen
Attached Files
File Type: zip bluechew.zip (10.4 KB, 2 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 25
Reputation: Dancealot is an unknown quantity at this point 
Solved Threads: 0
Dancealot Dancealot is offline Offline
Light Poster

Re: Sercurity Settings.

 
0
  #4
Aug 27th, 2008
Sorry. The my_finder, is the finder class, that I have tried to make. It should work, but I will change the name of it, to MyFinder.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,267
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: Sercurity Settings.

 
0
  #5
Aug 27th, 2008
LOL, you forgot to provide source images that you use with your VisualMIDlet (no worry I got replacement).
The problem with your application is that from your VisualMIDlet you are trying to call upon another MIDlet in bad fashion. It is possible to call MIDlet from MIDlet (here is example), but it is recommended to use only one. Secondly I never did it so I will not able to advice if you push for two MIDlet option.
However if you decide to go for single MIDlet then you will need to modify one of them. I would modify VisaulMIDlet as BlueChewMIDlet is giving you solid ground to work from and it will be much easier to attach class with application GUI to it.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 25
Reputation: Dancealot is an unknown quantity at this point 
Solved Threads: 0
Dancealot Dancealot is offline Offline
Light Poster

Re: Sercurity Settings.

 
0
  #6
Aug 29th, 2008
Ok. I will try to do that. Thanks for the help mate.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 1072 | Replies: 5
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC