• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

Java用zxing生产二维码时提示MatrixToImageWriter refers to the missing t

以下是跟着视频一起敲的代码,但是出错了,错误提示为:The method writeToPath(BitMatrix, String, Path) from the type MatrixToImageWriter refers to the missing type Path,不知道是什么原因,有哪位朋友知道可以帮帮忙吗


package com.chen.zxing;


import java.io.File;
import java.nio.file.Path;
import java.util.HashMap;


import javax.sound.midi.Patch;



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;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;


public class QR_CreateCode {
        public static void main(String[] args) {
                int width=300;
                int height=300;
                String format="png";
                String content="www.baidu.com";
               
                HashMap hints=new HashMap();
                hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
                hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
                hints.put(EncodeHintType.MARGIN, 2);
               
               
                try {
                        BitMatrix bitMatrix=new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hints);
                  Path file1=new File("E:/NewJavaWorkpacel/img.png").toPath();
            
                         MatrixToImageWriter.writeToPath(bitMatrix, format, file1);
                         
                } catch (WriterException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }        }


}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与2

我也遇到同样的问题,我找到的原因是因为我jar包打包的时候用的jdk1.6,然而我的工程的jdk是1.7。所以导致jdk不匹配,改完就好了

使用道具 举报

将catch (WriterException e)里面的writer删掉就可以;因为无法捕捉io错误,所以扩大exception范围就可以了 删掉就相当于扩大范围

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!