Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException when using String[]

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I make reference to my earlier thread in this forum:
http://www.coderanch.com/t/395645/java/java/howto-return-multiple-values-parent
As stated earlier, I am trying to pass parameters between applets.
For testing, I've created a class for holding the data that needed to be passed back. It is an array.

From the following startup applet, I instantiate the above applet

The startupUpApplet invokes another applet, which evtly flushes the data to the TXDetailData as well as update the index for the next lot of data (in other words, it keeps multiple records):

ANd finally I added a little CleanUp routine which displays the updated TXDetailData to test the whole thing

When I tested it this morning without index it worked fine.
After I've added the index, and recompiled Java console reports the runtime error "NullPointerException".
Can anyone help out please?
TIA :-)
[ February 24, 2004: Message edited by: Jim Yingst ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nowhere in this code do you initialize the two array variables var_acctName and var_unitCost; they're both null. Hence, when you try to use them, you'll get a NullPointerException. You need to actually create an array object using "new" -- i.e.,
String[] var_acctName = new String[100];
I used "100" as the size because it wasn't clear to me what you'd want to size to be. If you don't know either, you should consider using ArrayLists instead of arrays, since ArrayLists can grow as needed.
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrgh, you hit the nail on the head.
Let's say a client buys pizza, pasta, salat, what ever over the Net, where each dish has its own JFrame, and I've to save the client's selection to a singleton pending flushing to the database on commit, then there is no way for me to know how big the order will be, hence I wouldn't know how big the array or hashtable should be.
That's my dilemma.
Having said that, I agree array[100] is probably on the extravagant side.
Thanks for taking time to look at my issue :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic