Need help ->java.lang.ArrayIndexOutOfBoundsException: 0

Hi everybody

Can anyone help me on this error?

Thanks for any idea.

mySiti

publicstaticvoid main(String[] args)throws Exception{

Picture pic =new Picture(args[0]);

if (args.length != 1){

System.out.println ("Incorrect number of errors!");

System.exit(0);

pic.show();

}//end if

}// end main()

[762 byte] By [mySitia] at [2007-10-2 22:05:51]
# 1
i dont see any error on your code...make sure that when you run your application you should provide an agrument for that.. like this:>java MyApps hello world
angeles1016a at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 2

public static void main(String[] args) throws Exception {

Picture pic = new Picture(args[0]);

if (args.length != 1) {

System.out.println ("Incorrect number of errors!");

System.exit(0);

pic.show(); // this doesnt make any sense because of System.exit() above!

} //end if

}// end main()

angeles1016a at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 3

How is the Picture class implemented? When I compiled and ran the code, I received no errors (I commented out the lines referring to pic of course).

Here's what I ran:

public class Test{

public static void main(String[] args) throws Exception {

//Picture pic = new Picture(args[0]);

if (args.length != 1) {

System.out.println ("Incorrect number of errors!");

System.exit(0);

//pic.show();

} //end if

}// end main()

}

muzica at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks muzic.I still have that error.Can I e-mail the programs to your respective e-mail?myStiMessage was edited by: mySitiMessage was edited by: mySiti
mySitia at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 5

try this:

public class Test{

public static void main(String[] args) throws Exception {

Picture pic = new Picture(args[0]);

if (args.length != 1) {

System.out.println ("Incorrect number of errors!");

System.exit(0);

} //end if

pic.show();

}// end main()

}

imtireda at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 6
> try this:> ...> Picture pic = new Picture(args[0]);Um, and if there were no arguments, then that would cause the exception in question. Obviously you'd need to check the number of arguments *first*.
warnerjaa at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 7
it may be better to post..that way, more than one person is working to solve the problem.if you can post, an example java file of your classes, the steps you took, and possibly where the error is occurring, that would help alot in finding a solution.how does this sound?
muzica at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 8
When I execute using JCreator, there error is ->java.lang.ArrayIndexOutOfBoundsException: 0But when using java Picture X.tif, there is no error.Whats different between them?Thanks for any idea.mySiti
mySitia at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 9
issuing via java, you are passing in a parameter. you will probably need to do the same if you are running in JCreator. here's something on that idea on the JCreator site http://www.jcreator.com/faq.htm#30other than that, I do not know JCreator since I use eclipse.
muzica at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...
# 10
Ok, I got the right output.Thanks everybody.mySiti
mySitia at 2007-7-14 1:22:26 > top of Java-index,Java Essentials,Java Programming...