package zSave; import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.util.HashMap; import java.util.Map; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.WriterException; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; public class ZxingQrCodeUtil { public static void main(String[] args) throws WriterException, IOException { int width=300;; String contents="png"; int height=300; String format="http://baidu.com";//也可以写中文 //定义二维码参数 Map<EncodeHintType,Object> hints=new HashMap<EncodeHintType,Object>() hints.put(EncodeHintType.CHARACTER_SET,"utf-8"); //错误行---> BitMatrix bitMatrix=new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height, hints); File file=new File("E://QR_test."+format); Path p=new File("E://QR_test2."+format).toPath();/* if (!file.exists()) { file.createNewFile(); }*/ MatrixToImageWriter.writeToPath(bitMatrix, format, p); System.out.println("生成成功"); } }
上面是代码,下面是错误信息:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at com.google.zxing.common.CharacterSetECI.getCharacterSetECIByName(CharacterSetECI.java:114)
at com.google.zxing.qrcode.encoder.Encoder.encode(Encoder.java:96)
at com.google.zxing.qrcode.QRCodeWriter.encode(QRCodeWriter.java:78)
at com.google.zxing.MultiFormatWriter.encode(MultiFormatWriter.java:102)
at zSave.ZxingQrCodeUtil.main(ZxingQrCodeUtil.java:40)
我的encode()方法里的参数 BarcodeFormat.QR_CODE不能用,一用就出现上面的错误,是运行的时候出错,
查了但不知道具体解决办法,说是语法错误???,
这里请各位大神帮忙解答 。
相关分类