2012-05-11 2 views
3

다음 코드를 작성했습니다. 카메라 플레이어를 만드는 데 사용됩니다. 나는 노키아 폰으로 테스트했다. 잘 작동하고 카메라를보고 기능을 사용할 수 있습니다.삼성 전화에서 j2me의 카메라를 열 수 없습니다.

하지만 문제는 삼성 휴대 전화에서 코드를 테스트 할 때 미디어 예외가 발생하고 결국 애플리케이션에서 나가야한다는 것입니다. 이 코드로 인해 내장 된 카메라 기능 (예 : 삼성 휴대 전화)도 작동하지 않습니다. 그래서 그 이유는 무엇입니까?

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; 

} 첫번째

+0

그래서 예외는 무엇입니까? 예외 처리 접근법에 대해 작업해야합니다 ... – home

+0

예외 처리가 의미하는 것은 ... 예외가 발생한 곳을 확인할 수 없습니다 (어쩌면'if (mPlayer == null)'입니까? – home

+0

"리소스를 사용할 수 없습니다. 응용 프로그램을 종료합니다."라는 미디어 예외가 발생했습니다. –

답변

1

것부터, 당신은 당신이 심비안 폰을 사용하지 않는 printStackTrace() 거의 쓸모 에뮬레이터의 외부는 것을 인식해야합니다.

당신은 대신 ExceptionError 분리의 java.lang.Throwable을 사용할 수 있습니다

당신은 테스트 동안 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 
} 
 

어떤 코드 행이 어떤 예외를 throw하는지 정확히 알았 으면 질문을 업데이트/다시 게시 할 수 있습니다.

관련 문제