FileReader is already defined in this compilation unit error Java

谁说我不能喝 提交于 2019-12-20 07:27:15

问题


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??

Here is my code:

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.


回答1:


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.




回答2:


Just rename your class "FileReader" to different toxicity, in order not to be confused.



来源:https://stackoverflow.com/questions/37141863/filereader-is-already-defined-in-this-compilation-unit-error-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!