0

我正在使用 QRGen 库ByteArrayOutputStream为 QR 码生成一个并为其生成位图图像。

我已将以下 3 个 jar 导入到我的项目中:

  • qrgen-1.0.jar
  • zxing-core-1.7.jar
  • zxing-j2se-1.7.jar

这是生成二维码ByteArray的方法:

public Bitmap qrBitmapFromString(String qrText){
    ByteArrayOutputStream out = QRCode.from(qrText).to(ImageType.PNG).withSize(300, 300).stream();
    byte[] data = out.toByteArray();
    Bitmap bmp = BitmapFactory.decodeByteArray (data,0,data.length, null);
    return bmp;
}

但我收到以下错误:

03-05 12:39:31.089: E/AndroidRuntime(1479): FATAL EXCEPTION: main
03-05 12:39:31.089: E/AndroidRuntime(1479): java.lang.NoClassDefFoundError: java.awt.image.BufferedImage
03-05 12:39:31.089: E/AndroidRuntime(1479):     at com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage(MatrixToImageWriter.java:48)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at com.google.zxing.client.j2se.MatrixToImageWriter.writeToStream(MatrixToImageWriter.java:75)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at net.glxn.qrgen.QRCode.stream(QRCode.java:99)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at co.emuze.emuzepay.PayCardFragment.qrBitmapFromString(PayCardFragment.java:27)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at co.emuze.emuzepay.PayCardFragment.onCreateView(PayCardFragment.java:23)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:795)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:998)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.BackStackRecord.run(BackStackRecord.java:622)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1330)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.Activity.performStart(Activity.java:4474)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1928)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.ActivityThread.access$600(ActivityThread.java:122)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.os.Looper.loop(Looper.java:137)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at android.app.ActivityThread.main(ActivityThread.java:4340)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at java.lang.reflect.Method.invokeNative(Native Method)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at java.lang.reflect.Method.invoke(Method.java:511)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-05 12:39:31.089: E/AndroidRuntime(1479):     at dalvik.system.NativeStart.main(Native Method)

什么会导致这种情况?

4

3 回答 3

0

堆栈跟踪回答了您的问题。java.awt类在 Android 中不存在。您不能使用使用 AWT 的库。你不能使用 QRGen,或者至少不能使用它的这一部分。

于 2013-03-05T12:11:08.897 回答
0

2.0-SNAPSHOT 应该解决这个问题https://oss.sonatype.org/content/repositories/snapshots/net/glxn/qrgen/android/2.0-SNAPSHOT/

https://github.com/kenglxn/QRGen

于 2014-05-23T18:46:01.537 回答
0

2.0-SNAPSHOT 在 android 上运行良好,并且在上周变得更快。可以在这里找到一个例子:https ://github.com/atomfrede/qrgen-android-example

于 2014-08-21T18:58:04.973 回答