This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Array error suggestion needed" Watch "Array error suggestion needed" New topic
Author

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.
____________________________________________________
CODE:
for (int h = 1 ; h < 10 ; h++ )
{
System.out.println(h);
panel[h] = new Panel();
panel[h].setLayout(new GridLayout(0,1));

for (int v = 1; v < 10 ; v++ )
{
txt[v] = new TextField(1);
System.out.print(v);
panel[h].add(txt[v]);
}

add(panel[h]);
}
___________________________________________________

Regards
KKH


if (!WorkHard){
System.out.println("Fail!!!");
}
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
author
Sheriff

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: http://aspose.com/file-tools
 
subject: Array error suggestion needed