我已按照本教程使用表面视图拍摄图像。
https://examples.javacodegeeks.com/android/core/ui/surfaceview/android-surfaceview-example/
这是有效的,但我正在尝试在片段内做同样的事情(我有一个带有Tablayout的viewpager)
我收到错误:
surfaceHolder.addCallback(this);
我可以使用什么而不是“这个”可以使用片段?
感谢您的帮助
Logcat显示了这个
07-17 11:02:25.555: E/AndroidRuntime(14878): FATAL EXCEPTION: main
07-17 11:02:25.555: E/AndroidRuntime(14878): Process: com.mytodo, PID: 14878
07-17 11:02:25.555: E/AndroidRuntime(14878): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.takePicture(android.hardware.Camera$ShutterCallback, android.hardware.Camera$PictureCallback, android.hardware.Camera$PictureCallback)' on a null object reference
07-17 11:02:25.555: E/AndroidRuntime(14878): at com.mytodo.SecondTab.capturePicture(SecondTab.java:78)
07-17 11:02:25.555: E/AndroidRuntime(14878): at com.mytodo.SecondTab$2.onClick(SecondTab.java:62)
07-17 11:02:25.555: E/AndroidRuntime(14878): at android.view.View.performClick(View.java:4789)
07-17 11:02:25.555: E/AndroidRuntime(14878): at android.view.View$PerformClick.run(View.java:19881)
07-17 11:02:25.555: E/AndroidRuntime(14878): at android.os.Handler.handleCallback(Handler.java:739)
07-17 11:02:25.555: E/AndroidRuntime(14878): at android.os.Handler.dispatchMessage(Handler.java:95)
07-17 11:02:25.555: E/AndroidRuntime(14878): at android.os.Looper.loop(Looper.java:135)
07-17 11:02:25.555: E/AndroidRuntime(14878): at android.app.ActivityThread.main(ActivityThread.java:5294)
07-17 11:02:25.555: E/AndroidRuntime(14878): at java.lang.reflect.Method.invoke(Native Method)
07-17 11:02:25.555: E/AndroidRuntime(14878): at java.lang.reflect.Method.invoke(Method.java:372)
07-17 11:02:25.555: E/AndroidRuntime(14878): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
07-17 11:02:25.555: E/AndroidRuntime(14878): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
07-17 11:02:28.058: I/Process(14878): Sending signal. PID: 14878 SIG: 9