2014-02-10 52 views
1

好吧,所以也許有一個原因。我還是這個新手。這是我的代碼。在完成方法中。即時消息得到這條線上的錯誤:當我打開相機或手機時,camera.setParameters(p);。那是導致錯誤的那條線。如果我評論它。相機可能會保持不動。然後我在camera.stopPreview();行發生錯誤。當我的相機改變方向時,我的應用程序無故崩潰

public void strobeTimer182() { 
superStrobe = new CountDownTimer(857, 10) { 

    public void onTick(long millisUntilFinished) { 
     textView2.setText("seconds remaining: " + millisUntilFinished 
       /2); 

     if (millisUntilFinished % 5 == 0 
       || millisUntilFinished % 2 == 0 
       || millisUntilFinished % 3 == 0 
       || millisUntilFinished % 7 == 0) { 

      p.setFlashMode(Parameters.FLASH_MODE_TORCH); 
      camera.setParameters(p); 
      camera.startPreview(); 

     } else { 

      p.setFlashMode(Parameters.FLASH_MODE_OFF); 
      camera.setParameters(p); 
      camera.stopPreview(); 
      textView2.setText("off"); 
     } 

    } 

    public void onFinish() { 
     textView2.setText("done!"); 
     // Set the flashmode to off 
     p.setFlashMode(Parameters.FLASH_MODE_OFF); 
     // Pass the parameter ti camera object 
     camera.setParameters(p); 
     //camera.stopPreview(); 
     textView2.setText("off"); 

    } 
}.start(); 
superStrobe.onFinish(); 

}

+2

使用LogCat檢查與您的崩潰相關的Java堆棧跟蹤。 – CommonsWare

+0

@CommonsWare我在我的手機上有一個logcat應用程序。它給了我一個錯誤的線。這就是我去看看,我不知道什麼是一個Java堆棧跟蹤。 – losethequit

+0

「我的手機上有一個logcat應用程序」 - 取決於您手機的操作系統級別,這可能不起作用。使用開發工具,如IDE訪問DDMS,查看LogCat。 「我不知道java堆棧跟蹤是什麼」 - 這在任何有關Java開發的嚴肅書籍以及無數網站中都有涉及。 – CommonsWare

回答

0

添加到您的activity.Hope它可以幫助:)

android:configChanges="orientation|keyboardHidden|screenSize" 
+0

這可能會有幫助,但是,如果我顯示插頁式廣告onResume();鎖定屏幕的方向意味着當用戶打開手機時我會放開錢。並且創建應用程序的類型時,他們可能想要以任何方向使用手機。 – losethequit

+0

我認爲這與相機的狀態沒有切換到onResume()有關。生命週期majiggy, – losethequit

+0

它不會鎖定屏幕方向,它只是避免方向更改問題,我只想嘗試一次。 –

0
 public void strobeTimer182() { 
    superStrobe = new CountDownTimer(857, 1) { 

     public void onTick(long millisUntilFinished) { 

      if (millisUntilFinished % 2 == 0) { 

       p.setFlashMode(Parameters.FLASH_MODE_TORCH); 
       camera.setParameters(p); 
       camera.startPreview(); 
       p.setFlashMode(Parameters.FLASH_MODE_OFF); 
       camera.setParameters(p); 
       camera.stopPreview(); 

      } else { 

       p.setFlashMode(Parameters.FLASH_MODE_TORCH); 
       camera.setParameters(p); 
       camera.startPreview(); 
       p.setFlashMode(Parameters.FLASH_MODE_OFF); 
       camera.setParameters(p); 
       camera.stopPreview(); 

      } 
      if (millisUntilFinished == 0) { 

       p.setFlashMode(Parameters.FLASH_MODE_TORCH); 
       camera.setParameters(p); 
       camera.startPreview(); 
       p.setFlashMode(Parameters.FLASH_MODE_OFF); 
       camera.setParameters(p); 
       camera.stopPreview(); 

      } 

     } 

     public void onFinish() { 
      // causes errors 
     } 
    }.start(); 
    superStrobe.onFinish(); 
} 

 public void strobeTimer182() { 
    superStrobe = new CountDownTimer(857, 1) { 

     public void onTick(long millisUntilFinished) { 



       p.setFlashMode(Parameters.FLASH_MODE_TORCH); 
       camera.setParameters(p); 
       camera.startPreview(); 
       p.setFlashMode(Parameters.FLASH_MODE_OFF); 
       camera.setParameters(p); 
       camera.stopPreview(); 


     } 

     public void onFinish() { 
      // causes errors 
     } 
    }.start(); 
    superStrobe.onFinish(); 
} 

第一個選項,如果你想循環通過三個以上的州,然後將其設置回第一個狀態。

第二個爲閃光燈的開關效果工作,但我選擇了第一個。

相關問題