• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Preston Thornton
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you been able to compile the java file into a .class file?
 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you check if you have class file in place?
 
Preston Thornton
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Preston Thornton
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry,

You wrote Java Threads . . . Wow!

Thank for helping the little guys and girls :-)
 
Henry Wong
author
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic