Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

code compiles with no errors but doesn't not create a class with pdf fields

 
Zubi Pen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hava a PdfFormGenerator.java file that takes a pdf document
loops throught all the fields and creates a class file and converts
the fieldnames into something java can use in a method name,. basically
sets all the set and get method.

I have specified the location of my pdf form and the location of my java code. The file
compiles with no errors, however when I run the file I get the following msg and it
doesn't create the class file

PdfFormGenerator : 0
java.lang.ArrayIndexOutOfBoundsException: 0
at hsc.student.PdfFormGenerator.main(PdfFormGenerator.java:138)
Press any key to coninue...

Any ideas how I can get this to work. Thanks

Here is the code:

 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PdfFormGenerator gen = new PdfFormGenerator(args[0], args[1]);

This means the program expects at least two arguments on the command line. Any less and it will throw the error you've seen. Considering index 0 is already invalid you have given no arguments at all.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you passing any arguments when you call the program ?
Your mainmethod is expecting two arguments which it passes to the PdfFormGenerator constructor.
 
Zubi Pen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I pass the two arguments to the PdfFormGenerator constructor, I think I need to pass the Form name and the class name but I thought I did do that in the PdfFormGenerator Constructor on line 3 and 4:



Thanks for the replies,
Zub
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but in the constructor, you still expect two Strings. You try to get these strings from the command line arguments, but you haven't given any.

Basically, you are calling it similar to this:

Instead, you should call it as this:

[ November 01, 2007: Message edited by: Rob Prime ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic