This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "null pointer exception " Watch "null pointer exception " New topic
Author

null pointer exception

depak khatri
Greenhorn

Joined: Jul 05, 2010
Posts: 5
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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!>


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null pointer exception
 
Similar Threads
Deleting duplicate integers from a vector!!!
How to (re)paint an AWT applet faster
array to graphic mapping
Scanner class help
help in fixing the error