开发者

NoClassDefFoundError: android.graphics.YuvImage (compiles but doesn't run)

i'm reposting this question because i'm not sure if i asked it correctly before.:) i'm working on an app that includes face detection. the camera boots up ok. within the preview frame callback i instantiate a faceview object (this class handles the detection). this class can only detect faces in a bitmap, but the image from the callback is a YuvImage. i've compressed the image to jpeg then called a method to convert that jpeg to a bitmap, so the detection will work.

The problem i'm having is that eclipse is saying that there's a classnotfoundexception regarding the YuvImage that i'm using. i've downloaded the api8 which yuvimage is part of. there are no errors in the source code and it compiles ok. is there a reason why ecilipse can't load the yuvimage class? here's a snippet, thanks.

'code'

BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inPreferredConfig = Bit开发者_如何学运维map.Config.RGB_565;
Rect rectangle = new Rect(0, 0, width, height);
ByteArrayOutputStream bos = new ByteArrayOutputStream(imageData.length);
try{
    img = new YuvImage(imageData,ImageFormat.NV21,width,height,null);
}catch(Exception e){
    e.printStackTrace();
}
img.compressToJpeg(rectangle, 100, bos);
byte[] array = bos.toByteArray();


sourceImage = BitmapFactory.decodeByteArray(array, 0, array.length);

Exception trace:

02-10 11:53:07.298: ERROR/dalvikvm(2364): Could not find class 'android.graphics.YuvImage', referenced from method com.tecmark.FaceView.<init>
02-10 11:53:07.468: ERROR/AndroidRuntime(2364): Uncaught handler: thread main exiting due to uncaught exception
02-10 11:53:07.473: ERROR/AndroidRuntime(2364): java.lang.NoClassDefFoundError: android.graphics.YuvImage
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.tecmark.FaceView.<init>(FaceView.java:60)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.tecmark.cameraView$1.onPreviewFrame(cameraView.java:111)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.hardware.Camera$EventHandler.handleMessage(Camera.java:395)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.os.Looper.loop(Looper.java:123)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at android.app.ActivityThread.main(ActivityThread.java:4363)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at java.lang.reflect.Method.invokeNative(Native Method)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at java.lang.reflect.Method.invoke(Method.java:521)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-10 11:53:07.473: ERROR/AndroidRuntime(2364):     at dalvik.system.NativeStart.main(Native Method)


Make sure that you are targeting the proper version of the SDK. In Eclipse right click your project, select Properties and then Android. Api 8 should be selected as the project's build target.

You should also set the minimum SDK attribute in the manifest xml (this has nothing to do with the error though).


Make sure that the package com.tecmark.FaceView is available to your project. Something like:
package com.tecmark.FaceView should be present at the top of your code in this file.

HTH,
Sriram

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜