So when I compile, everything will compile just fine.

When I go to run the program, I get this error

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
	at ClientForNoDupCollection.main(ClientForNoDupCollection.java:20)

I go to look at line 20(actually 19-21)

public static void main(String args[]) {
		File file = new File(args[0]);
		Scanner cReader = null;

I'm attempting to be able to do command line execution of the files.

I'm not 100% sure where I went wrong there.

Recommended Answers

All 4 Replies

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

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.

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. :(

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.