0

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.

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by masijade
0

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

Edited by Taywin: n/a

0

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.

0

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

0

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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.