File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Array error suggestion needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Array error suggestion needed" Watch "Array error suggestion needed" New topic

Array error suggestion needed

Koh Khai Huat
Ranch Hand

Joined: Aug 05, 2005
Posts: 100
Hi guys

I am creating 9 text field in each panel. and i have to create a total of 9 panel in a applet but i have encounter a "null pointer exception" which i dun know where this error came from so i would like to ask if anyone can give any suggestion on this error Thx.
i need suggestion or any form of advice on how i could slove this error thanks in advance.
for (int h = 1 ; h < 10 ; h++ )
panel[h] = new Panel();
panel[h].setLayout(new GridLayout(0,1));

for (int v = 1; v < 10 ; v++ )
txt[v] = new TextField(1);



if (!WorkHard){
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
perhaps elsewhere in your program something is trying to access one of the
arrays at element[0], which would be null.

run your applet - when the npe is generated, open the java console and you
should see which line number is generating the error.

try taking everything back to 0-based, and see if you still get the npe

Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Or you didn't initialize the array?

panel = new Panel[numberOfPanels];

Anyway, this isn't Swing specific - moving to Java in General (beginner)...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I agree. Here's the link:
subject: Array error suggestion needed
It's not a secret anymore!