my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Java Error: java.lang.ArrayIndexOutOfBoundsException: 0 For Simple Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Error: java.lang.ArrayIndexOutOfBoundsException: 0 For Simple Program" Watch "Java Error: java.lang.ArrayIndexOutOfBoundsException: 0 For Simple Program" New topic
Author

Java Error: java.lang.ArrayIndexOutOfBoundsException: 0 For Simple Program

Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
Greetings Java Friends!

I am sitting work on my lunch hour, practicing some java coding right for Osborne's Teach Yourself JAVA (Joseph O'Neil) in the input and output chapter, and I am encountering a Java error.

C:\Documents and Settings\pthornton\My Documents\NetBeansProjects\JavaClassLibra
ries\src\JavaLibraries>java FileDemo c:\RC_address.txt

Exception in thread "main" java.lang.NoClassDefFoundError: FileDemo


using NetBeans 6.7.1 IDE. I am not sure why it is complaining about the Class definition. Thanks for the help and understanding in advance.


Charbel Keyrouz
Ranch Hand

Joined: Jun 10, 2005
Posts: 46
you should go to the following location:
C:\Documents and Settings\pthornton\My Documents\NetBeansProjects\JavaClassLibra
ries\src>
and then type the following command:
java JavaLibraries.FileDemo c:\RC_address.txt

when you execute a class call all the hierarchy of packages until you reach the desired class and make sure to be in the src folder.
Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
I tried the suggestion and I still got the same:


This was done at the command prompt. I believe I got the spelling and location right on the retype.
Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
have you been able to compile the java file into a .class file?
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
Can you check if you have class file in place?


SCJP 1.5(97%) My Blog
Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
I have not been able to compile the java files outside of the Netbeans IDE. Everything works that can be executed inside of the IDE. I may need to check and set the classpath manually, for these command line executions.
Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
Okay, I am getting IDE lazy. I when back to the directory "C:\Documents and Settings\pthornton\My Documents\NetBeansProjects\JavaClassLibraries\src\JavaLibraries" and ran the "C:\Program Files\Java\jdk1.6.0_11\bin\javac.exe" *.java and compiled all of the classes where I see the new files.


I then reran the following:

>java FileDemo c:\RC_address.txt

Then I encountered a new error set:


C:\Documents and Settings\pthornton\My Documents\NetBeansProjects\JavaClassLibraries\src\JavaLibraries>

The unsupported class version has me as a loss.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

The unsupported class version has me as a loss.


Basically, you are using a java compiler that is newer than the jvm. For example, if you compile code using the Java 5 compiler, and try to run it using a Java 1.4 jvm, you'll see this error.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
Okay, thank you. So, I need to specify the right JVM version, because I have 4 version of Java on my system. What is the command line option to point to the correct one?
Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
Henry,

You wrote Java Threads . . . Wow!

Thank for helping the little guys and girls :-)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Preston Thornton wrote:Okay, thank you. So, I need to specify the right JVM version, because I have 4 version of Java on my system. What is the command line option to point to the correct one?


Well, if you are going to use a particular one, then the best option is to set the PATH environment variable. If you want to do it from the command line, then you'll have to specify the complete path for the compiler and jvm... like...

c> /a/particular/jvm/that/you/want/bin/javac myclass.java

c> /a/particular/jvm/that/you/want/bin/java myclass


Henry
Preston Thornton
Ranch Hand

Joined: Jun 24, 2008
Posts: 80
Dang!

Yeah, this solution is a keeper. I will go back and update my Java path

C:\Documents and Settings\pthornton\My Documents\NetBeansProjects\JavaClassLibraries\src>
"C:\Program Files\Java\jdk1.6.0_11\bin\java" JavaLibraries.FileDemo c:\RC_address.txt
pathSeparatorChar = ;
separatorChar = \
getName() = RC_address.txt
getParent() = c:\
getAbssolutePath() = c:\RC_address.txt
getCanonicalPath() C:\RC_address.txt
getPath() = c:\RC_address.txt
getRead() = true
canWrite() = true

C:\Documents and Settings\pthornton\My Documents\NetBeansProjects\JavaClassLibraries\src>

Thanks.

Wayne State University
Detroit, Michigan 48202

Get Free Money to go to school AIM Higher (giving.wayne.edu)

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Error: java.lang.ArrayIndexOutOfBoundsException: 0 For Simple Program