When you run, how did you run it? If you use IDE (not command line execution), you may not pass the argument in the command to the method. As a result, your args[] array is size 0.
// correct command line
java ClientForNoDupCollection myfile.ext
// if the myfile.ext exists, it is OK here
// if it doesn't exist, File class will throw NPE
// incorrect
java ClientForNoDupCollection
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17
Then you need to show me your whole class code then. I can't pinpoint how it happen by seeing only this much portion of the code. :(
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17
So I tried what you referred to.
I get this error now.
java.lang.NullPointerException
at ClientForNoDupCollection.main(ClientForNoDupCollection.java:41)
Looked at line 41.
while (cReader.hasNext())
Looks like it's referring back to the top...as being null.
Uhm ...
public static void main(String args[]) {
File file = new File(args[0]);
Scanner cReader = null;
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,484
Solved Threads: 494
Skill Endorsements: 16