You Are Here:

Community: Developer Discussion Boards

#1 Old Problems with Camera. Camera run on java class and it failed on midlet. - 2008-04-17, 09:14

Join Date: Apr 2008
Posts: 21
Kaisser
Offline
Registered User
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.
Reply With Quote

#2 Old Re: Problems with Camera. Camera run on java class and it failed on midlet. - 2008-04-17, 11:23

Join Date: Nov 2007
Posts: 2,029
Location: Rome, Italy
Send a message via MSN to jappit Send a message via Skype™ to jappit
jappit's Avatar
jappit
Offline
Forum Nokia Champion
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


www.jappit.com - mobile and web blog
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ