为什么活动无法正确恢复?

时间:2019-06-26 15:57:15

标签: java android tensorflow-lite

由于试图按最右边的按钮查看打开的应用程序或使手机进入睡眠状态,因此在调用onPause和onStop之后,我试图使程序正确恢复。我不知道正确的电话是什么。我已经查找了一些有关此的信息,但是我发现所有的人都说要在onPause中调用super.onPause并在onResume中调用super.onResume,然后编写我的代码。这段代码不是我的,并且在恢复时崩溃并显示错误:

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


关于所有这些,我有两个问题:

  • 我可以通过注释掉第185-187行来使摄像机正常重启,但是我不知道这是否是正确的方法。注释?有想法吗?

  • 即使这可行,主活动也不会重新启动。这是这里的实际主要问题。我还想象这段代码肯定有问题,但无法弄清楚它是什么。关于如何解决它的任何建议?


主要活动代码链接: https://github.com/tensorflow/examples/blob/master/lite/examples/object_detection/android/app/src/main/java/org/tensorflow/lite/examples/detection/CameraActivity.java

1 个答案:

答案 0 :(得分:0)

我在问题中进行并提及的更改由于某种原因未能解决问题。我想这与在调用onStop或新的backgroundthread更改某些内容后回调设置不正确有关?

要解决此问题,我添加了

textureView.getSurfaceTextureListener().onSurfaceTextureAvailable(textureView.getSurfaceTexture(), textureView.getWidth(), textureView.getHeight());

Legacy .... java文件中第152行之前。

相关问题