0

我正在尝试读取已上传到我的 NXT 砖本地文件系统的 txt 文件的内容,但是当我尝试启动我的应用程序时,我得到了 NullPointerException

public static String line(String coord) throws Exception {

据我所知,nxt 无法识别文件的存在。我还尝试在我的计算机上使用 txt 文件副本的文件路径,但这也返回了 NullPointerException

BufferedReader br = new BufferedReader(new FileReader("Files\\test.txt"));

    try {
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();

        while (line != null) {
            sb.append(line);
          //  sb.append(System.lineSeparator());
            line = br.readLine();
        }
        String everything = sb.toString();

        coord = everything;
    } catch(Exception e) {
        System.out.println(e);
    }
    return coord;



  heres the whole error exception:

  java.lang.NullPointerException
at js.tinyvm.CodeUtilities.processMethod(CodeUtilities.java:388)
at js.tinyvm.CodeUtilities.processCode(CodeUtilities.java:736)
at js.tinyvm.MethodRecord.postProcessCode(MethodRecord.java:205)
at js.tinyvm.MethodRecord.postProcessCode(MethodRecord.java:143)
at js.tinyvm.ClassRecord.storeCode(ClassRecord.java:798)
at js.tinyvm.Binary.processCode(Binary.java:737)
at js.tinyvm.Binary.createFromClosureOf(Binary.java:326)
at js.tinyvm.TinyVMTool.link(TinyVMTool.java:97)
at js.tinyvm.TinyVMTool.link(TinyVMTool.java:48)
at lejos.pc.tools.NXJLink.start(NXJLink.java:134)
at lejos.pc.tools.NXJLink.run(NXJLink.java:101)
at lejos.pc.tools.NXJLink.start(NXJLink.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at lejos.pc.tools.ToolStarter.startTool(ToolStarter.java:31)
at lejos.pc.tools.NXJLink.main(NXJLink.java:28)

我想让我的 NXT 读取存储在其文件系统上的文件的内容,所以感谢您的帮助

4

1 回答 1

0

我使用以下代码检索我的坐标作为属性

    Properties p = new Properties();
    File f = new File("coords.txt");
    if(f.exists()) {
        FileInputStream in;
        try {
            in = new FileInputStream(f);
            p.load(in);
            in.close();
        } catch (Exception e) {
            System.err.println("Failed to load coordinates");
            System.err.println(e.getMessage());
            Button.waitForAnyPress();
            System.exit(0);
        }
    }else {
        System.out.println("No coordinates found");
        while(!Button.ESCAPE.isPressed())
        {Thread.yield();}
        System.exit(0);
    }
于 2019-02-13T16:15:30.527 回答