Zxing上编译错误
由于我没有用于开发目的的 G1,因此我会尽力使用模拟器。 也就是说,我正在尝试使用 ZXing (Zebra Zrossing) 库扫描 sdCard 中的 JPEG 图像或 PNG 图像。
我尝试更改 Android 项目中的代码,以便它从 sdCard 中的图像扫描,而不是从相机扫描,但没有任何运气。
我接下来所做的可能是我的问题的根源。
我尝试在新的 Android 项目中使用 JAVASE 代码,为“修改后的”CommandLineRunner 提供图像,事情是这样的:
Eclipse 将构建该项目,但不会运行它。 VM 日志向我展示了以下消息:
**02-08 20:47:45.916: WARN/dalvikvm(619): VFY: 无法解析静态方法 939: Ljavax/imageio/ImageIO;.read (Ljava/io/File;)Ljava/awt/图像/缓冲图像; 02-08 20:47:45.926: WARN/dalvikvm(619): VFY: 拒绝 0x0004 处的操作码 0x71 02-08 20:47:45.926:警告/dalvikvm(619):VFY:拒绝Lcom / magoco / fread / FRead; .decode2(Ljava / io / File; Ljava / util / Hashtable; Ljava / lang / String;)Ljava /语言/字符串; 02-08 20:47:45.926:警告/dalvikvm(619):验证程序拒绝了 Lcom/magoco/fread/FRead 类; 02-08 20:47:45.926: WARN/dalvikvm(619): 类 init 在 newInstance 调用中失败 (Lcom/magoco/fread/FRead;) 02-08 20:47:45.926:调试/AndroidRuntime(619):关闭虚拟机 02-08 20:47:45.926:警告/dalvikvm(619):threadid = 3:线程因未捕获的异常而退出(组= 0x40010e28) 02-08 20:47:45.937:错误/AndroidRuntime(619):未捕获的处理程序:线程主线程由于未捕获的异常而退出 02-08 20:47:45.946:错误/AndroidRuntime(619):java.lang.VerifyError:com.magoco.fread.FRead **
我在网上搜索了答案,有人说这是 Dalvikvm 上的常见错误,因为可能存在预编译的类或库(确实,在 Eclipse 之外),而 VM 不会能够使用它。
我在主要活动中发布我的代码:
package com.magoco.fread;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.TextView;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ResultParser;
public class FRead extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) this.findViewById(R.id.BarcodeResult);
try {
tv.setText(this.decodeOneArgument2("", false));
} catch (Exception e) {
e.printStackTrace();
}
}
public String decodeOneArgument2(String argument, boolean dumpResults)
throws Exception {
String barcode = "";
// File inputFile = new File(argument);
File inputFile = new File("sdcard/dcim/pueblo.JPG");
/* TESTING THAT I'VE GOT A FILE */
System.out.println("FILE " + inputFile.toString());
// decode(new URI(argument), hints);
decode2(inputFile, null, barcode);
return barcode;
}
public String decode2(File f, Hashtable<DecodeHintType, Object> hints,
String barcode) throws IOException {
/* IF I COMMENT THE NEXT LINE, IT RUNS BUT OF COURSE NO RESULT */
BufferedImage image;
try {
image = ImageIO.read(f);
} catch (IllegalArgumentException iae) {
throw new FileNotFoundException("Resource not found: " + f);
}
try {
MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(
image);
Result result = new MultiFormatReader().decode(source, hints);
ParsedResult parsedResult = ResultParser.parseResult(result);
barcode = " format: " + result.getBarcodeFormat()+ result.getText() + "\nParsed result:\n"+ parsedResult.getDisplayResult();
System.out.println(" format: " + result.getBarcodeFormat()+ result.getText() + "\nParsed result:\n"+ parsedResult.getDisplayResult());
//return result;
} catch (ReaderException e) {
System.out.println(": No barcode found");
return null;
}
return barcode;
}
}
提前致谢
monn3t
Since I don't own a G1 for development purposes, I am doing my best with the emulator.
This said, I am trying to scan a JPEG image or a PNG image in my sdCard, with the ZXing (Zebra Zrossing) library.
I tried to change the code in the Android project, so it would scan from an image in the sdCard, instead from the camera, without any luck.
What I did next is probably the root of my problem.
I tried to use the JAVASE code, within a new Android Project, to provide an image to the "modified" CommandLineRunner, and here is the thing:
Eclipse would build the project, but won't run it.
The VM log throuws me this message among others:
**02-08 20:47:45.916: WARN/dalvikvm(619): VFY: unable to resolve static method 939: Ljavax/imageio/ImageIO;.read (Ljava/io/File;)Ljava/awt/image/BufferedImage;
02-08 20:47:45.926: WARN/dalvikvm(619): VFY: rejecting opcode 0x71 at 0x0004
02-08 20:47:45.926: WARN/dalvikvm(619): VFY: rejected Lcom/magoco/fread/FRead;.decode2 (Ljava/io/File;Ljava/util/Hashtable;Ljava/lang/String;)Ljava/lang/String;
02-08 20:47:45.926: WARN/dalvikvm(619): Verifier rejected class Lcom/magoco/fread/FRead;
02-08 20:47:45.926: WARN/dalvikvm(619): Class init failed in newInstance call (Lcom/magoco/fread/FRead;)
02-08 20:47:45.926: DEBUG/AndroidRuntime(619): Shutting down VM
02-08 20:47:45.926: WARN/dalvikvm(619): threadid=3: thread exiting with uncaught exception (group=0x40010e28)
02-08 20:47:45.937: ERROR/AndroidRuntime(619): Uncaught handler: thread main exiting due to uncaught exception
02-08 20:47:45.946: ERROR/AndroidRuntime(619): java.lang.VerifyError: com.magoco.fread.FRead
**
I searched the web for an answer and I got someone saying that this is common error on the Dalvikvm due to the fact that there is might be a class or library that was precompiled (true, outside Eclipse) and the VM wouldn't be able to use it.
I am posting my code in the main Activity:
package com.magoco.fread;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.TextView;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.ReaderException;
import com.google.zxing.Result;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ResultParser;
public class FRead extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) this.findViewById(R.id.BarcodeResult);
try {
tv.setText(this.decodeOneArgument2("", false));
} catch (Exception e) {
e.printStackTrace();
}
}
public String decodeOneArgument2(String argument, boolean dumpResults)
throws Exception {
String barcode = "";
// File inputFile = new File(argument);
File inputFile = new File("sdcard/dcim/pueblo.JPG");
/* TESTING THAT I'VE GOT A FILE */
System.out.println("FILE " + inputFile.toString());
// decode(new URI(argument), hints);
decode2(inputFile, null, barcode);
return barcode;
}
public String decode2(File f, Hashtable<DecodeHintType, Object> hints,
String barcode) throws IOException {
/* IF I COMMENT THE NEXT LINE, IT RUNS BUT OF COURSE NO RESULT */
BufferedImage image;
try {
image = ImageIO.read(f);
} catch (IllegalArgumentException iae) {
throw new FileNotFoundException("Resource not found: " + f);
}
try {
MonochromeBitmapSource source = new BufferedImageMonochromeBitmapSource(
image);
Result result = new MultiFormatReader().decode(source, hints);
ParsedResult parsedResult = ResultParser.parseResult(result);
barcode = " format: " + result.getBarcodeFormat()+ result.getText() + "\nParsed result:\n"+ parsedResult.getDisplayResult();
System.out.println(" format: " + result.getBarcodeFormat()+ result.getText() + "\nParsed result:\n"+ parsedResult.getDisplayResult());
//return result;
} catch (ReaderException e) {
System.out.println(": No barcode found");
return null;
}
return barcode;
}
}
Thanks in Advance
monn3t
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
海,
我尝试从条形码中提取数据,这些是我遵循的步骤。
1.下载ZXing 1.3并解压。
2.通过设置属性,将解压后的 zxing floder 中的 core/src 和 androidtest/src 添加到 android 应用程序中。
使用此链接设置属性,http://groups.google.com/ group/zxing/browse_thread/thread/7d8693e6e42408f2
现在包含以下代码,
这可能会对您有所帮助。
Hai,
I tried to extract the data from the Barcodes and these are the steps i followed.
1.Download ZXing 1.3 and extract it.
2.Add the core/src and androidtest/src from the extracted zxing floder to the android application by setting the property.
use this link to set the property,http://groups.google.com/group/zxing/browse_thread/thread/7d8693e6e42408f2
Now include the following code,
This may be helps you.
这是相关项目的 Sean。
您正在尝试在 Android 中使用适用于 Java SE 的代码。 Java SE 中的一些库不在 Android 中,例如 ImageIO。
查看 android/ 中的代码,它使用 Android 特定的类来加载图像。
This is Sean from the project in question.
You are trying to use the code intended for Java SE in Android. Some of the libraries in Java SE are not in Android, like ImageIO.
Look at the code in android/ which uses Android-specific classes to load images.