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

发布于 2024-10-16 22:43:45 字数 2483 浏览 5 评论 0原文

我重新发布这个问题是因为我不确定我之前问的是否正确。:)我正在开发一个包含面部检测的应用程序。相机启动正常。在预览帧回调中,我实例化一个面部视图对象(此类处理检测)。该类只能检测位图中的人脸,但回调中的图像是 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)

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 = 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);

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很酷又爱笑 2024-10-23 22:43:45

确保您的目标是正确的 SDK 版本。在 Eclipse 中右键单击您的项目,选择“属性”,然后选择“Android”。应选择 API 8 作为项目的构建目标。

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

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).

眼眸里的那抹悲凉 2024-10-23 22:43:45

确保包 com.tecmark.FaceView 可用于您的项目。类似于:
package com.tecmark.FaceView 应出现在该文件中代码的顶部。

HTH,
斯里拉姆

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文