由于按下最右邊的按鈕查看打開的應(yīng)用程序或讓手機(jī)進(jìn)入睡眠狀態(tài),我試圖讓程序在調(diào)用 onPause 和 onStop 后正確恢復(fù)。我不熟悉正確的電話是什么。我已經(jīng)查找了一些關(guān)于此的信息,但我發(fā)現(xiàn)的只是人們說在 onPause 中調(diào)用 super.onPause,在 onResume 中調(diào)用 super.onResume,然后編寫我的代碼。然而,這段代碼不是我的,并且在恢復(fù)時(shí)崩潰并出現(xiàn)錯(cuò)誤:java.lang.RuntimeException: Unable to resume activity {org.tensorflow.lite.examples.detection/org.tensorflow.lite.examples.detection.DetectorActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.startPreview()' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.startPreview()' on a null object reference代碼可在以下位置找到: https: //github.com/tensorflow/examples/blob/master/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/LegacyCameraConnectionFragment .java關(guān)于這一切, 我有兩個(gè)問題:我可以通過注釋掉第 185-187 行讓相機(jī)正確重啟,但我不知道這是否是正確的方法。評論?想法?即使這有效,主要活動(dòng)也不會(huì)重新啟動(dòng)。這是這里的實(shí)際主要問題。我還認(rèn)為這段代碼一定有問題,但無法弄清楚它是什么。關(guān)于如何解決它的任何建議?主要活動(dòng)代碼鏈接: https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/CameraActivity.java
1 回答

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
由于某種原因,我在問題中所做和提到的更改并沒有解決問題。我想這與調(diào)用 onStop 后未正確設(shè)置回調(diào)或新的后臺線程改變了什么有關(guān)?
為了修復(fù)它,我添加了
textureView.getSurfaceTextureListener().onSurfaceTextureAvailable(textureView.getSurfaceTexture(), textureView.getWidth(), textureView.getHeight());
在 Legacy... .java 文件的第 152 行之前。
添加回答
舉報(bào)
0/150
提交
取消