> 文章列表 > The type javax.smartcardio.CardTerminal is not accessible

The type javax.smartcardio.CardTerminal is not accessible

The type javax.smartcardio.CardTerminal is not accessible

许久没有发布过学习心得了,今天在使用java连接读卡器的时候,想要参考网友的例子进行连接,遇到了The type javax.smartcardio.CardTerminal is not accessible问题,网友也有提示说需要在module-info 增加requires 暂时不知道什么原因。
贴图,展示下错误解决过程,希望能让大家更快解决问题。

 

 

package cardTerminal;

import java.util.List;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.TerminalFactory;

public class connectPCSC {
    /
     * main function, to list all the PC/SC readers connected to your PC
     * */
    public static void main(String[] args) {
        // to show the list of available terminals
        TerminalFactory factory = TerminalFactory.getDefault();
        //list of readers(empty)
        List<CardTerminal> terminalsList;  //list最好能明确元素的类型
        try {
            //get list of reader form the terminal
            terminalsList = factory.terminals().list();
            //print list of readers to the console
            System.out.println(terminalsList.toString());
        }catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

}

成功,显示PC/SC读卡器名称

谢谢各位网友的无私的经验分享,希望我的搬运可以更好的帮助初学者