Reputation: 735
I am using Android Studio on macbook for creating simple camera app following official android documentation. However, when I try to call camera.setPreviewDisplay(SurfaceHolder)
I am getting following error:
Error:(29, 16) error: cannot find symbol method setPreviewDisplay(SurfaceHolder)
Also my CameraPreview class is as follows:
package com.opencv.camerapreview;
import android.content.Context;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback{
private SurfaceHolder surfaceHolder;
private Camera mCamera;
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera=camera;
this.surfaceHolder= getHolder();
this.surfaceHolder.addCallback(this);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mCamera.setPreviewDisplay(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}
It looks like this is some linking issue in Android Studio. Can anybody shed some light on why this could happen and solution. Thanks
Upvotes: 3
Views: 4031
Reputation: 106
You have imported
import android.graphics.Camera;
and you should import
import android.hardware.Camera;
or even
import android.hardware.camera2;
if you are targeting API 21 and above.
Upvotes: 9