无法读取以下程序中存储的名称 import java.lang.*; 导入java.util.*; 导入java.io.*; 公共类名 { 静态扫描仪输入=新扫描仪(系统输入); public void timeloop()//不需要。仅用于键入效果 { 对于(int i=0;i

无法读取以下程序中存储的名称 import java.lang.*; 导入java.util.*; 导入java.io.*; 公共类名 { 静态扫描仪输入=新扫描仪(系统输入); public void timeloop()//不需要。仅用于键入效果 { 对于(int i=0;i,java,debugging,Java,Debugging,您应该有一个main方法来运行您的程序,因此将该方法的签名更改为: import java.lang.*; import java.util.*; import java.io.*; public class Names { static Scanner in=new Scanner(System.in); public void timeloop() //unnecessary. for typing effect only { for(int i=0;i<=75000000;

您应该有一个
main
方法来运行您的程序,因此将该方法的签名更改为:

import java.lang.*;
import java.util.*;
import java.io.*;
public class Names
{
static Scanner in=new Scanner(System.in);

public void timeloop() //unnecessary. for typing effect only
{
    for(int i=0;i<=75000000;i++)
    {
    }
}

public void read()throws IOException //Stores in file
{
    FileWriter fout=new FileWriter("E:\\Vista Data\\Pranjal\\Desktop\\Names.txt",true);
    BufferedWriter bout=new BufferedWriter(fout);
    PrintWriter pout=new PrintWriter(bout);

    String out="\fAccessing E:\\Vista Data\\Pranjal\\Desktop\\Names.txt";

    for(int i=0;i<out.length();i++)
    {
        System.out.print(out.charAt(i));
        timeloop();
    }
    System.out.println("");
    System.out.print("Enter any key to continue... ");
    in.next();

    System.out.println("\fEnter number of students");
    int x=in.nextInt();

    System.out.print("");
    in.nextLine();

    for(int n=0;n<x;n++)
    {
        System.out.println("\nEnter a name");
        String name = in.nextLine();
        pout.println(name);
    }

    pout.flush();
    pout.close();

    main();
}

public void write()throws IOException //Reads from file
{
    FileReader fin=new FileReader("E:\\Vista Data\\Pranjal\\Desktop\\Names.txt");
    BufferedReader bin=new BufferedReader(fin);

    String out="Accessing E:\\Vista Data\\Pranjal\\Desktop\\Names.txt";

    for(int i=0;i<out.length();i++)
    {
        System.out.print(out.charAt(i));
        timeloop();
    }
    System.out.println("");
    System.out.print("Enter any key to continue... ");
    String temp=in.next();

    System.out.print("\f");

    String[] str=new String[100];
    int wordcnt=0;

    System.out.println("ERROR");
    while((str[wordcnt]=bin.readLine())!=null)
    {
        System.out.println("Name of student:"+(str[wordcnt].toUpperCase()));
        wordcnt++;
    }

    main();
}

public int cnt()throws IOException //counts number of lines in file
{
    FileReader fin=new FileReader("E:\\Vista Data\\Pranjal\\Desktop\\Names.txt");
    BufferedReader bin=new BufferedReader(fin);

    int cnt=0;
    String[] str=new String[100];
    while((str[cnt]=bin.readLine())!=null)
    {
        cnt++;
    }
    return cnt;
}

public String opt() //Accepts option from the user
{
    System.out.println("\fIf you would like to read the stored names, enter R");
    System.out.println("If you would like to append the file, enter A");
    System.out.println("If you would like to exit the program, enter E");

    String opt=(in.next());

    return opt;
}

public static void main()throws IOException
{
    Names name=new Names();

    switch(name.opt())
    {
        case "R":
        {
            System.out.println("\fNumber of students:"+(name.cnt())+"\n");
            name.write();
        }
        break;

        case "A":
        {
            name.read();
        }
        break;

        case "E":
        {
            System.exit(0);
        }
        break;

        default:
        {
            System.out.println("Wrong input... ABORTING");
            System.exit(0);
        }
    }
}
}
由于方法签名已更改,您必须在方法
read()
write()
中修改对此
main
方法的方法调用,如下所示:

public static void main(String[] args)throws IOException
通过进行这些更改,您的程序可以正常运行


最后,只是一个建议,
read()。你没有为此付钱。对不起,我不想费心调试你的代码来找出问题所在。你为什么不告诉我们?
main(null)