Could not open camera on Samsung phone in j2me

I wrote the following code snippet. It is used to create a camera. I tested it on Nokia phones. It works great, and I can see the camera and use its functionality.

But the problem is that when the code is tested on a Samsung phone, it throws a Media exception and ultimately needs to exit the application. Because of this code, my built-in camera functionality (i.e. on a samsung phone) also stops working. So what is the reason for this?

    public void startCamera()
{
    try
    {
        try 
        {
            // if player==null
            player = createPlayer();
        } 
        catch (Exception ex) 
        {
            ex.printStackTrace();
            ErrorDialog.show(ex, "We are exiting the application.",
                        "Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
                    public void actionPerformed() {
                        m_objMIDlet.exitApp();
                    }
            });
        }
        try 
        {
            player.realize(); 
            player.prefetch();
        }
        catch (MediaException ex) 
        {
            ex.printStackTrace();
            ErrorDialog.show(ex, "We are exiting the application.",
                        "Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
                    public void actionPerformed() {
                        m_objMIDlet.exitApp();
                    }
            });
        }




        //Grab the video control and set it to the current display.
        videoControl = (VideoControl)(player.getControl("VideoControl"));
        if (videoControl == null)
        {
            //discardPlayer();
            stopCamera();
            ErrorDialog.show("Unsupported:\n"+
                 "Can't get video control\n"+
                 "We are exiting the application.",
                    "Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
                public void actionPerformed() {
                    m_objMIDlet.exitApp();
                }
            });
        }

        mediaComponent = new MediaComponent(player);
        mediaComponent.setFocusable(false);
        m_cameraScreen.showCamera(mediaComponent);
        start();
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
        //discardPlayer();
        stopCamera();
        ErrorDialog.show("Sorry,Resources unavailable.\nWe are exiting the application.",
                        "Exit", new com.auric.qrev.scanqrcode.lwuit.ui.Action(){
                    public void actionPerformed() {
                        m_objMIDlet.exitApp();
                    }
        });
    }

}

    private Player createPlayer()throws MediaException, Exception 
{
    Player mPlayer = null;
    // try capture://image first for series 40 phones
    try 
    {
        mPlayer = Manager.createPlayer("capture://image");
    }
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    catch (Error e) 
    {
        e.printStackTrace();
    }

    // if capture://image failed, try capture://video
    if (mPlayer == null) 
    {
        try 
        {
            mPlayer = Manager.createPlayer("capture://video");
        } 
        catch (Exception e)
        {
            e.printStackTrace();
            throw new MediaException("Sorry,Resources unavailable.");
        }
    }

    if(mPlayer == null)
        throw new Exception("Sorry,Resources unavailable.");

    return mPlayer;

}

+3
source share
1 answer
First of all, you should understand that it is printStackTrace()practically useless outside the emulator if you do not use a Symbian phone.

java.lang.Throwable Exception Error

, , String lcdui Form :


try {
    // do something that could potentially fail
} catch (Throwable th) {
    myDebugLcduiForm.append("potential failure number xx." + th + th.getMessage());
    // if necessary, throw a new RuntimeException
}

, / , , - .

+1

All Articles