Windows 7 x64
Bad problem description I know, but it's really hard to explain.
Basically I was trying to make some tweaks to an old program in IntelliJ after recently reformatting Windows and reinstalling java and all that jazz. No matter what I changed in the program, the output wasn't changing. Didn't matter what I commented out or changed.
So after a bit of frustration I decided to do some base testing to make sure I wasn't just losing my mind. I made an entirely new directory. And in that directory I made one file (using Sublime Text, not IntelliJ). Your classic "Hello World" program.
public class FrequencyCounter {
public static void main(String args[]) {
System.out.println("Hello World");
}
}
That was the only file in the directory. Ran
javac FrequencyCounter.java
Seemed to compile fine, no errors, generated a FrequencyCounter.class file in the directory. Ran
java FrequencyCounter
And got this error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at FrequencyCounter.main(FrequencyCounter.java:50)
Obviously this doesn't make any sense. It's like it's not running the FrequencyCounter class in that directory, but some older cached one somewhere else. Just for sanity's sake I copied the file, but changed it to HelloWorld.java
and public class HelloWorld { ..... }
, that compiles and runs fine (in the same directory).
If it helps:
D:\Copy\Code\Learning\CS\IntelliJ\test>java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
D:\Copy\Code\Learning\CS\IntelliJ\test>javac -version
javac 1.7.0_07
Assuming what you tell us is correct, it is running a FrequencyCounter class from somewhere else. The most likely thing is that your classpath is set to a directory or jar that already has a FrequencyCounter class in it, and it's running that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With