FileReader已在此编译单元错误Java中定义 [英] FileReader is already defined in this compilation unit error Java

查看:447
本文介绍了FileReader已在此编译单元错误Java中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在读取 .txt文件以使用它来实现Dijkstra的算法,但是每次尝试编译它时,都会出现 FileReader已在此编译单元中定义错误,同时突出显示了我一开始就导入了它。但是,如果我将其删除,则当我尝试读取错误类型的文件时,它将引发构造函数错误。我在这里错过了什么?

So I'm working on reading in a ".txt" file to use it to implement Dijkstra's algorithm, but every time I try to compile it gives me a "FileReader is already defined in this compilation unit" error while highlighting where I imported it in the beginning. If I take this out, however, it throws a constructor error when I'm trying to read in the file that it's of the wrong type. What am I missing here??

这是我的代码:

import java.io.BufferedReader;
import java.io.File;
//import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class FileReader
{
    public ArrayList main1()
    {
        System.out.println("got here");
        try
        {
            BufferedReader in = new BufferedReader(new FileReader(new File("input1.txt")));

如果需要的话,我可以提供更多,但这是所有错误浮出水面的地方。

I can provide more if needed, but this is where all of the errors crop up.

推荐答案

您的类的名称与java.io包中的FileReader相同(您在上面已注释掉)。将您的类重命名为诸如TextFileReader或InputFileReader之类的名称,或将完全限定的类名称用于java.io.FileReader。

Your class is named the same as FileReader in the java.io package (you have commented out above). Rename your class to something else like TextFileReader or InputFileReader or use the fully qualified class name for java.io.FileReader.

这篇关于FileReader已在此编译单元错误Java中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆