×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    21

    Problems with Camera. Camera run on java class and it failed on midlet.

    Hello!

    I have a class that shows the camera correctly.
    It´s the code:

    Code:
    package hello;
    
    import java.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.VideoControl;
    import javax.microedition.amms.*;
    import javax.microedition.amms.control.camera.*;
    import javax.microedition.io.file.*;
    import javax.microedition.io.*;
    
    
    public class CamaraMovil extends MIDlet 
               implements CommandListener, ItemStateListener{
        
        private Player player;
        private VideoControl vidCtrl = null;
        private Command exitCommand = new Command("Exit", Command.ITEM, 1);
        
        private Display display;
        private Form vidForm;
        private Item videoItem;
        
        
        
        public CamaraMovil() {
            vidForm = new Form("Camera Player");
            display = Display.getDisplay(this);
            display.setCurrent(vidForm);
            vidForm.addCommand(exitCommand);
            vidForm.setCommandListener(this);
            
            try {           
                player = Manager.createPlayer("capture://video");
                player.prefetch();
                player.realize();
                
                vidCtrl = (VideoControl)player.getControl(
                    "VideoControl");
                if (vidCtrl != null) {
                    videoItem = (Item)vidCtrl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null);
                    vidCtrl.setDisplaySize(140, 140);
                    vidForm.append(videoItem);
                } else {
                    System.out.println("Error: Can not create VideoControl");
                    return;
                }
                     
                 
            } catch (MediaException me) {
                me.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
    
            public void startApp() {
            try {
                player.start();
                
            } catch (MediaException me) {
                me.printStackTrace();
            }
        }
        
            public void destroyApp(boolean unconditional) {
            closePlayer();
            notifyDestroyed();
        }
            
       private void closePlayer() {
            if (player != null) {
                player.close();
                player = null;
            }
        }
       
               
        protected void pauseApp() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        public void commandAction(Command arg0, Displayable arg1) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        public void itemStateChanged(Item arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
           
    }
    This class runs ok. If I used this class directly, I don´t have any problem.

    I will like to have a midlet that calls the CamaraMovil class. I realized the call in this way:

    Code:
    public void commandAction(Command command, Displayable displayable) {                                               
            // write pre-action user code here
            // Después de inicializar todo, tenemos la pantalla de opciones.
            // Pulsamos OK, que debería ser "Ver Camara", pero bueno.
            if (displayable == form) {                                           
                if (command == VerCamara) {                                         
                    // write pre-action user code here
                    // El comando OK, corresponde a VerCamara.
                    switchDisplayable(null, getForm1());                                           
                    // write post-action user code here
                    //Se supone que ya hemos creado la nueva pantalla, ahora
                    // faltaría "encender" la cámara.
                    
                    Camara = new CamaraMovil();
    
    ....
    I obtained an 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(MIDletSuiteImpl.java:281)
    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 hello.CamaraMovil.<init>(CamaraMovil.java:29)
    at hello.HelloMIDlet.commandAction(HelloMIDlet.java:118)
    at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(Display.java:1992)
    at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(Display.java:2825)
    at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(DefaultEventHandler.java:303)
    at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(AutomatedEventHandler.java:670)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+194)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+51)


    WHY? Why the code is ok if only runs the class ??

    I hope someone can help me.

    THANKS.


    Pd: Excusme, I have an horrible english.

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Problems with Camera. Camera run on java class and it failed on midlet.

    Hi Kaisser,

    the problem is that you cannot instantiate a MIDlet from within another MIDlet. So, you should rewrite your CamaraMovil class (for example making it extend directly Form) so that it could be usable within your midlets.

    Pit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×