2012-02-14 3 views
-1

나는 안드로이드 LiveWallpaper catch와 함께 이상한 오류가 발생했습니다. 나는 그것은 2.3ish 주위의 API의 작동이 설정하면 :Strange Catch Try Finally Error

Canvas canvas = null; 
    //Keep trying till wallpaper is set. 
    //Error around here.. 
    try 
    { 
     canvas = this._surfaceHolder.lockCanvas(null); 
     synchronized (this._surfaceHolder) 
     { 
      this.onDraw(canvas); 
     } 
    } 

    finally 
    { 
     if(canvas != null) 
     { 
      this._surfaceHolder.unlockCanvasAndPost(canvas); 
     } 
    } 

을 그리고 이것은 & 벌집이 (실제 장치에서 테스트) ICS에서 작동

Canvas canvas = null; 
    //Keep trying till wallpaper is set. 
    //Error around here.. 
    try 
    { 
     canvas = this._surfaceHolder.lockCanvas(null); 
     synchronized (this._surfaceHolder) 
     { 
      this.onDraw(canvas); 
     } 
    } 

    finally 
    { 
     if(canvas != null) 
     { 
      this._surfaceHolder.unlockCanvasAndPost(canvas); 
     } 
    } 

라이브 배경 화면은 "설정"할 때 오류가 발생합니다 . (서비스는 "예외 잠금 서비스"에 실패합니다.) 하나의 컴파일에서 둘 다 작동하도록하려면 어떻게해야합니까? 두 가지 버전이 필요하지 않습니다.

+3

차이점을 찾을 수 없습니다. – weston

+0

여기에는 실제로 질문이 없습니다. 당신이 가진 오류는 무엇입니까? 그리고 나는 눈이 멀거나 미쳐 가고 있기 때문에 두 코드 조각의 차이점은 무엇입니까? 그들은 저와 동일하게 보입니까? –

+1

@weston이 말한 것, 플러스 - 당신이 시도하고 마침내 사용하는 경우, 당신도 뭔가 잡기 안되니? 던져진 예외를 잡기 때문에 앱이 충돌합니다. – RivieraKid

답변

4

시도 캐치의 구문은 다음과 같습니다

try { 
    // Code 
} catch (<the Exception type to catch> ex) { 
    // Exception handling code 
} finally { 
    // Code for after 
} 

주의 :이 프로그램은 사용자가 지정한 예외를 잡을 것입니다. 가능한 모든 예외를 다루지 않으면 처리되지 않습니다. 오라클의 Java 자습서에서 catch blocks을 참조하십시오. 시도 캐치의

+0

도움이 되었습니까? – Goofy

+0

그에게 기회를주세요! – weston

+0

@ weston k 괜찮아요. – Goofy

0

구문은 {

} 잡기 {예외 전자) // 코드가 예외 을 잡으려고} 시도 드디어 {

} 정확히 자바 규칙

에 따라

쓰기 코드