android - I/art: Can not find class: -
hello there new such kind of android studio error. may warning have been facing issue of not finding classes.
actually i'm working on android camera api application , problem front facing camera preview stretch. happens 2-3 devices huawei p8 lite. device stretches camera preview when switched front facing camera!
i have camera preview class as:
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 camera previewcamera = camera; if(previewcamera!=null){ // supported preview sizes msupportedpreviewsizes = previewcamera.getparameters().getsupportedpreviewsizes(); } else{ previewcamera=camera; // supported preview sizes msupportedpreviewsizes = previewcamera.getparameters().getsupportedpreviewsizes(); } // install surfaceholder.callback notified when // underlying surface created , destroyed. mholder = getholder(); mholder.addcallback(this); // deprecated setting, required on android versions prior 3.0 mholder.settype(surfaceholder.surface_type_push_buffers); setkeepscreenon(true); setpreview(); } @override public void surfacecreated(surfaceholder surfaceholder) { try{ //when surface created, can set camera draw images in 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 application orientation, need stop preview, rotate , start again if(mholder.getsurface() == null)//check if surface ready receive camera data return; try{ previewcamera.stoppreview(); } catch (exception e){ //this happen when trying camera if it's not running } //now, recreate camera preview try{ //set camera preview on every preview change setpreview(); //in case preview 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 focusable true this.setfocusable(true); //set touch able true this.setfocusableintouchmode(true); //set camera display orientation lock previewcamera.setdisplayorientation(90); //get camera parameters camera.parameters parameters = previewcamera.getparameters(); //set preview size parameters.setpreviewsize(mpreviewsize.width, mpreviewsize.height); //set parameter previewcamera.setparameters(parameters); }catch(exception exp){ log.i(exception_key,"from setpreview: "+exp.tostring()); } } @override public void surfacedestroyed(surfaceholder surfaceholder) { //our app has 1 screen, we'll destroy camera in surface //if using more screens, please move code activity try{ //handle in activity onresume , 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() stop updating preview surface. previewcamera.stoppreview(); // important: call release() release camera use other // applications. applications should release camera // during onpause() , re-open() during onresume()). previewcamera.release(); previewcamera = null; } } //end of outer class here }
i have been tackling issue since last few days , getting same stretched effect on custom camera preview.
so method 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; (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; (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 of stretching camera preview on front facing camera. log cat data follow:
it showing lines starting as: i/art: can not find class:. newbiew have no idea mean?
make sure have following dependencies added apps build.gradle file.
compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:recyclerview-v7:24.1.1'
from screenshot, missing classes found in recyclerview support library (defaultitemanimator , simpleitemanimator).
Comments
Post a Comment