Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null pointer exception

 
depak khatri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am making a prog to enter values in a textfield array and sum all those values but
i am getting null pointer exception when i click on sum button and clear button
please help me out
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this code



For each value of i and j, you're creating a whole new 2-dimensional array, and putting a TextField into one element. The next time around the loop, you create another new array, discarding the first one, and put a TextField into a different element; etc. You get NullPointerExceptions because the end result is an array which contains just one TextField (the very last one) and a lot of nulls.

Just remove that "t=new TextField[n][n];" line. You create the array when the member variable is declared, so you don't need to create it again!>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic