我/艺术:不能找到类: [英] I/art: Can not find class:

查看:216
本文介绍了我/艺术:不能找到类:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是新的这种类型的Android Studio错误。可能是它只是一个警告,但我一直面临一个问题,不能找到类。

Hello there I am new to such kind of Android Studio Error. May be its just a warning but I have been facing an issue of not finding the classes.

在Android Camera API应用程序,问题是,我的前面相机预览是伸展。它只会发生在2-3个设备,如 Huawei p8 lite

Actually I'm working on an Android Camera API Application and the problem is that my Front Facing Camera Preview is Stretch. It only happens with some 2-3 devices like Huawei p8 lite. The device stretches its camera preview when switched to front facing camera!

我的相机预览类为:

public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {

    //Variables de' Preview
    private SurfaceHolder mHolder;
    private List<Camera.Size> mSupportedPreviewSizes;
    private Camera.Size mPreviewSize;
    private int FOCUS_AREA_SIZE=300;
    public static Camera previewCamera;
    ////////////////////////

    //protected LOGGER keys
    protected final String EXCEPTION_KEY="xception";
    //////////////////////////

    public CameraPreview(Context context, Camera camera) {
        super(context);

        //get the camera
        previewCamera = camera;

        if(previewCamera!=null){
            // supported preview sizes
            mSupportedPreviewSizes = previewCamera.getParameters().getSupportedPreviewSizes();
        }
        else{
            previewCamera=camera;
            // supported preview sizes
            mSupportedPreviewSizes = previewCamera.getParameters().getSupportedPreviewSizes();
        }

        // Install a SurfaceHolder.Callback so we get notified when the
        // underlying surface is created and destroyed.
        mHolder = getHolder();
        mHolder.addCallback(this);
        // deprecated setting, but required on Android versions prior to 3.0
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        setKeepScreenOn(true);
        setPreview();
    }

    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        try{
            //when the surface is created, we can set the camera to draw images in this surfaceholder
            setPreview();

            previewCamera.setPreviewDisplay(surfaceHolder);
            previewCamera.startPreview();

            if(CameraActivity.cameraId==1){
                previewCamera.setFaceDetectionListener(faceDetectionListener);
                previewCamera.startFaceDetection();
            }
        } catch(Exception exp){
            Log.i(EXCEPTION_KEY,"FROM surfaceCreated: "+exp.toString());
        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
        //before changing the application orientation, you need to stop the preview, rotate and then start it again

        if(mHolder.getSurface() == null)//check if the surface is ready to receive camera data
            return;

        try{
            previewCamera.stopPreview();
        } catch (Exception e){
            //this will happen when you are trying the camera if it's not running
        }

        //now, recreate the camera preview
        try{
            //set the camera preview on every preview change
            setPreview();

            //in case the preview is still stretched bingo! Then...

//            Camera.Parameters params = previewCamera.getParameters();
//            List<Camera.Size> sizes = params.getSupportedPreviewSizes();
//            Camera.Size optimalSize = PreviewSizeParameters.getOptimalPreviewSize(sizes,i2,i3);
//            params.setPreviewSize(optimalSize.width,optimalSize.height);
//            previewCamera.setParameters(params);

            previewCamera.setPreviewDisplay(mHolder);
            previewCamera.startPreview();

            if(CameraActivity.cameraId==1){
                previewCamera.setFaceDetectionListener(faceDetectionListener);
                previewCamera.startFaceDetection();
            }
        } catch(Exception exp){
            Log.i(EXCEPTION_KEY,"FROM surfaceChanged: "+exp.toString());
        }
    }

    public void setPreview(){
        try{
            //set the focusable true
            this.setFocusable(true);
            //set the touch able true
            this.setFocusableInTouchMode(true);
            //set the camera display orientation lock
            previewCamera.setDisplayOrientation(90);

            //get the camera parameters
            Camera.Parameters parameters = previewCamera.getParameters();
            //set the preview size
            parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
            //set the parameter
            previewCamera.setParameters(parameters);
        }catch(Exception exp){
            Log.i(EXCEPTION_KEY,"FROM setPreview: "+exp.toString());
        }
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
        //our app has only one screen, so we'll destroy the camera in the surface
        //if you are using with more screens, please move this code your activity
        try{
            //handle in Activity onResume and onPause
        }catch(Exception exp){
            Log.i(EXCEPTION_KEY,"FROM surfaceDestroyed: "+exp.toString());
        }
    }

    //Override Methods here
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        try{
            final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
            final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);
            setMeasuredDimension(width, height);

            if (mSupportedPreviewSizes != null) {
                mPreviewSize = PreviewSizeParameters.getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
            }
        }catch(Exception exp){
            Log.i(EXCEPTION_KEY,"FROM onMeasure: "+exp.toString());
        }
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void stopPreviewAndFreeCamera() {

        if (previewCamera != null) {
            // Call stopPreview() to stop updating the preview surface.
            previewCamera.stopPreview();

            // Important: Call release() to release the camera for use by other
            // applications. Applications should release the camera immediately
            // during onPause() and re-open() it during onResume()).
            previewCamera.release();

            previewCamera = null;
        }
    }


    //end of outer class here
}






自从最近几天以来,我一直在处理这个问题,并对我的自定义相机预览产生同样的拉伸效果。


I have been tackling with this issue since last few days and getting the same stretched effect on my custom camera preview.

所以我的最佳预览大小的方法是:

So my method for getting optimal preview sizes is:

public class PreviewSizeParameters {

    //protected LOGGER keys
    protected static final String EXCEPTION_KEY = "xception";
    //////////////////////////

    public static Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
        final double ASPECT_TOLERANCE = 0.1;
        double targetRatio = (double) h / w;

        if (sizes == null) return null;

        Camera.Size optimalSize = null;
        double minDiff = Double.MAX_VALUE;

        int targetHeight = h;

        for (Camera.Size size : sizes) {
            double ratio = (double) size.width / size.height;
            if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }

        if (optimalSize == null) {
            minDiff = Double.MAX_VALUE;
            for (Camera.Size size : sizes) {
                if (Math.abs(size.height - targetHeight) < minDiff) {
                    optimalSize = size;
                    minDiff = Math.abs(size.height - targetHeight);
                }
            }
        }
        return optimalSize;
    }
}






问题



问题是仅在前置相机上拉伸相机预览。我的日志猫数据如下:


The problem

The problem is of stretching camera preview on just front facing camera. My log cat data is as follow:

它显示了一些开头的行: I / art:找不到类:。因为我是新手,所以我不知道他们是什么意思?

It is showing some lines starting as: I/art: Can not find class:. As I am a newbiew so I have no idea what do they mean?

推荐答案

确保您已将以下依赖项添加到您的应用 build.gradle 文件。

Make sure you have the following dependencies added to your apps build.gradle file.

compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'

在截图中,这些缺少的类位于recyclerview支持库(DefaultItemAnimator和SimpleItemAnimator)中。

From the screenshot, those missing classes are found in the recyclerview support library (DefaultItemAnimator and SimpleItemAnimator).

这篇关于我/艺术:不能找到类:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆