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 null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "null pointer exception " Watch "null pointer exception " New topic

null pointer exception

depak khatri

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

Joined: Jul 08, 2003
Posts: 24195

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:
subject: null pointer exception
It's not a secret anymore!