线程“ AWT-EventQueue-0”中的异常java.util.NoSuchElementException代码正在更早地工作,但现在不起作用

时间:2019-03-13 15:57:15

标签: java

private void jLabel23MouseClicked(java.awt.event.MouseEvent evt) {          

     Scanner sc; 

     try {

       sc = new Scanner (new FileReader("src\\main\\Profiles.txt"));
        String name, newPrice,fname,lname,male,female,a,cin,add,group;
        String line ="",content="";
            name = userNameField6.getText();


        while(sc.hasNextLine())
            {
                line = sc.nextLine();
                Scanner lineinput = new Scanner(line);
                lineinput.useDelimiter("/");
                String gr = lineinput.next();
                String firstname = lineinput.next();  
                String lastname = lineinput.next();
                String age = lineinput.next();
                String gender = lineinput.next();
                String contact = lineinput.next();
                String address = lineinput.next();


                if(name.equals(firstname))
                {



                    line = "";

                }
                content = content +line;

            }

                JOptionPane.showMessageDialog(null, "Profile Has Been Deleted");

                sc.close();
                FileWriter writer,writer2;
                try {
                    writer = new FileWriter("src\\main\\Profiles.txt");
                    writer2 = new FileWriter("src\\main\\Profiles_1.txt");

                writer.write(content);
                writer.close();
                 writer2.write(content);
                writer2.close();


                } catch (IOException ex) {

                }
            } catch (FileNotFoundException ex) {

        }

}  

它会告诉我这个错误 enter image description here
这段代码早先起作用,然后突然停止了工作。基本上,它所做的只是将一行文本文件更改为空白文件。我是编程新手,不知道该怎么做。

0 个答案:

没有答案