Forums Register Login

NullPointerException when using String[]

+Pie Number of slices to send: Send
Hi.
I make reference to my earlier thread in this forum:
https://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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 :-)
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1037 times.
Similar Threads
ArrayList - still getting null pointer exception?
howto: print records from Hashtable?
System.out.println not responding ?
Totally baffled with ArrayList throwing NullPOinterException !
Need Help with ArrayList - NullPointerException
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:14:34.