NoClassDefFoundError:android.graphics.YuvImage(编译但不运行)

时间:2011-02-10 12:08:38

标签: android noclassdeffounderror

我正在重新发布这个问题,因为我不确定我之前是否正确地问过它。:)我正在开发包含面部检测的应用程序。相机启动好了。在预览帧回调中,我实例化一个faceview对象(该类处理检测)。此类只能检测位图中的面,但回调中的图像是YuvImage。我已经将图像压缩为jpeg然后调用了将该jpeg转换为位图的方法,因此检测将起作用。

我遇到的问题是eclipse说有关于我正在使用的YuvImage的classnotfoundexception。我已经下载了yuvimage所属的api8。源代码中没有错误,编译好。有没有理由为什么ecilipse无法加载yuvimage类?这是一个片段,谢谢。

'代码'

BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inPreferredConfig = Bitmap.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);

异常追踪:

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)

2 个答案:

答案 0 :(得分:2)

确保您定位适当版本的SDK。在Eclipse中右键单击您的项目,选择Properties,然后选择Android。应该选择Api 8作为项目的构建目标。

您还应该在清单xml中设置最小的SDK属性(这与错误无关)。

答案 1 :(得分:1)

确保您的项目可以使用包com.tecmark.FaceView。类似的东西:
package com.tecmark.FaceView应出现在此文件的代码顶部。

HTH,
斯利拉姆