File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array error suggestion needed

 
Koh Khai Huat
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you didn't initialize the array?

panel = new Panel[numberOfPanels];

Anyway, this isn't Swing specific - moving to Java in General (beginner)...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic