2013-03-05 46 views
0

我正在使用QRGen庫爲QR碼生成ByteArrayOutputStream併爲其生成位圖圖像。使用QRGen庫生成QR碼時出錯

我已經進口了3個以下罐子到我的項目:

  • qrgen-1.0.jar
  • 斑馬線核-1.7.jar
  • 斑馬線-J2SE-1.7.jar

這是生成QR碼的方法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) 

什麼原因呢?

回答

0

堆棧跟蹤回答你的問題。 java.awt類在Android中不存在。您不能使用使用AWT的庫。你不能使用QRGen,或者至少不能使用它。

+0

有沒有辦法將該類導入到android? – 2013-03-05 12:14:58

+0

編號AWT是Java的桌面應用程序,在Android上沒有位置。直接使用zxing,它支持Android。你不能使用'javase /'中的位 – 2013-03-05 12:38:26