Newbie NullPointerException

A

a2zasics

Hi,
I am getting a NullPointer error executing the ActionListener below.
Can anyone tell me whats wrong. The same code is working for another
Actionlistener. I am really not getting whats wrong here. I have
commented almost everything i could. Any ideas...

-SP


private class getSummary implements ActionListener {
private int day, month,year;
private String desc, tran;
private int amt;
double sum[], grandSum;
private int i;
public void actionPerformed(ActionEvent event) {
int tfmonth = Integer.parseInt(tf1.getText().trim());
BufferedReader data; // (Declare the variable before the
try {
data = new BufferedReader(new FileReader("rec.txt"));
boolean test = false;
for (i=0;i<=tItems;i++) sum=0;
ta.setText("");
while (!test) {
try {
String s = data.readLine();
ta.append(s+"\n");
test = (s == null);
if (!test) {

//StringTokenizer t = new StringTokenizer(s,"|");
//month = Integer.parseInt(t.nextToken());
//day = Integer.parseInt(t.nextToken());
//year = Integer.parseInt(t.nextToken());
//tran = t.nextToken();
//desc = t.nextToken();
//amt = Integer.parseInt(t.nextToken());
//for (i=0;i<=tItems;i++){
// if((month == tfmonth)&& (tran.equals(tList))){
// sum = sum+amt;
// } else {
// }
//}
} else {
}
} catch (IOException e){

}

}

//for (i=0;i<=tItems;i++){
// ta.append(tList+" "+sum+"\n");
// grandSum = grandSum+sum;
//}
//
//ta.append( "Total "+grandSum+ "\n");
//ta.append("--------------------------------------\n");

//try {
// data.close();
//} catch (IOException e){
// ta.append("ERROR closing rec.txt");
//}
}
catch (FileNotFoundException e) {
ta.append("File rec.txt not found\n");
}

}
}
 
C

Curt King

I am getting a NullPointer error executing the ActionListener below.
Can anyone tell me whats wrong. The same code is working for another
Actionlistener. I am really not getting whats wrong here. I have
commented almost everything i could. Any ideas...
public void actionPerformed(ActionEvent event) {
int tfmonth = Integer.parseInt(tf1.getText().trim());
BufferedReader data;

Where is tf1 declared or initialized?

Curt
 
P

Phil...

It is a good idea to check the return value from method invocations.
"data" for example.
It is a good idea to check the number of tokens on a line prior to parsing
them.
"t.countTokens" for example.
It is a good idea to use some concrete value for a loop termination.
"tList[].length" for example.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top