hi All,
I was trying to generate QR code using the ZXing utility. I was able to do it on my windows system, however, when I tried to use the same code as part of a small android app, it gave me errors. The error message is like this:
11-05 21:50:12.917: ERROR/AndroidRuntime(273): java.lang.NoClassDefFoundError: java.awt.image.BufferedImage
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(MatrixToImageWriter.java:48)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at com.google.zxing.client.j2se.MatrixToImageWriter.writeToStream(MatrixToImageWriter.java:75)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at com.infineon.qrtest.ZXingTestActivity.encodeQR(ZXingTestActivity.java:109)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at com.infineon.qrtest.ZXingTestActivity$1.onClick(ZXingTestActivity.java:70)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at android.view.View.performClick(View.java:2408)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at android.view.View$PerformClick.run(View.java:8816)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at android.os.Handler.handleCallback(Handler.java:587)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at android.os.Looper.loop(Looper.java:123)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at java.lang.reflect.Method.invoke(Method.java:521)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-05 21:50:12.917: ERROR/AndroidRuntime(273): at dalvik.system.NativeStart.main(Native Method)
I think, this is because AWT is not supported on Android OS, is that correct. In that case what is the way to generate QR code using the features/functionality supported by Android ?
Would appreciate if someone can point me to some sample code, URL etc.
The code, I'm using in android is as following:
<code snippet>
public void encodeQR(String text, int height, int width)
throws WriterException, FileNotFoundException, IOException {
// (ImageIO.getWriterFormatNames() returns a list of supported formats)
// could be "gif", "tiff", "jpeg"
String imageFormat = "png";
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, width, height);
// FileOutputStream fos = new FileOutputStream(new File(sdCard + "/"
// + "myQR.png"));
FileOutputStream fos = openFileOutput("myqr.png", Context.MODE_PRIVATE);
MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, fos);
Log.d(TAG, "Written QR image at:" + sdCard + "myQR.png");
}
<code snippet>
Thanks in advance.
Regards,
KK