"Cannot find constructor".

Caporegime
Joined
12 Mar 2004
Posts
29,962
Location
England
java.io is imported so I don't see what the problem is here? Says it can't find the filereader constructor.

Code:
BufferedReader bufferedreader = new BufferedReader(new FileReader("items.txt"));
 
That normally suggests you have tried to initialise using parameters that don't map to a constructor. However, I had a quick look and it seems a FileReader object can be created with a String parameter specifying a filename.

Do you have a more precise error message and/or some code?
 
Ah, was calling the class FileReader which it didn't like. :o

It's a namespace collision, it's generally a bad idea to name your classes the same as the common Java libraries but you can get around it by explicitly specifying the namespace such as:

BufferedReader bufferedreader = new BufferedReader(new java.io.FileReader("items.txt"));

You are explicitly specifying that you want to use the FileReader from the java.io package. Java will use the 'closest' definition of a type so if you import a type that is defined in the class, the one in the class will have priority. Any good IDE such as Eclipse warns you when this happens but it's one of those problems you can spend hours trying to figure out if you don't notice it.
 
Last edited:
Back
Top Bottom