Reputation: 5086
I have an Eclipse project where I imported the library "OpenCSV" as an external JAR. The library is now shown in my project under "referenced libraries".
However, when I call:
CSVReader reader = new CSVReader(new FileReader(csvPath));
Eclipse throws an error saying that the constructor CSVReader is not defined. csvPath is of type String.
Any thoughts?
EDIT: Screenshot
Upvotes: 2
Views: 2325
Reputation: 2858
My full solution is listed here, try working with CSVParser instead, which is available from the Apache Commons and works much more readily!
Upvotes: 0
Reputation: 124275
I may be mistaken (I don't use this library and don't know history of its package names) but it looks like autoEvoSuite
is your own package.
If that is the case then you have class name conflict (actually there is no conflict, you are just using wrong class) since your class is also named CSVReader
so inside method readCVS
you are not calling constructor of au.com.bytecode.opencsv.CSVReader
, but constructor of your own class autoEvoSuite.CSVReader
, and since your class doesn't have
public CSVReader(FileReade reader){...}
constructor, compiler informs you about this problem.
To solve this problem consider renaming your class, or be explicit and say which class exactly you want to use by writing its full-package-name like
au.com.bytecode.opencsv.CSVReader reader = new au.com.bytecode.opencsv.CSVReader(new FileReader(csvPath));
Upvotes: 5
Reputation: 4185
You are calling a constructor for your own class CSVReader
that doesn't exist! Either rename your class and create a new instance of au.com.bytecode.opencsv
, or delete the respective line, make sure you import au.com.bytecode.opencsv.CSVReader
, and re-create the line.
Alternatively - but I'm unsure whether this is what you'd want - you can make your CSVReader
(optimally under another name), extend au.com.bytecode.opencsv.CSVReader
and override the respective constructor.
I guess your problem was caused when you used auto-complete for CSVReader
and didn't pick the class from the right package?
Upvotes: 2
Reputation: 1009
you have to try and catch FileNotFoundException and see the code below.
public FileReader(String fileName) throws FileNotFoundException {
super(new FileInputStream(fileName));
}
you can modify it like following
try {
CSVReader reader = new CSVReader(new FileReader(csvPath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Upvotes: 2
Reputation: 4995
You need to add the relevant JAR in the project's Build Path in order to have it built.
Your Java Project (Right Click)--> Properties --> Java Build Path --> Libraries --> Add JARs/Add External JARs
Upvotes: 0