hi, i am trying to read the file and parse the info to the text field of the awt gui form thing. i got the info out successfully by testing with the "system.out.pritnln(variable )" .. however, using the variable values wouldn't successfully set to the TextFeild for output.
//the first 7 lines are the exact info i need from the text. however i couldn't get them to appear in the TextField
1
bob
23 pond street
40.0
32.3
f
23
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Reader.readRecord(Reader.java:123)
at Reader.actionPerformed(Reader.java:65)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
below is my method to read the file
public void readRecord()
{
int recNum;
String name, address;
double hours, rate, grossPay, fedTax, stateTax;
char sex;
int age;
try
{
recNum = scanner.readInt();
name= scanner.readUTF();
address = scanner.readUTF();
hours= scanner.readDouble();
rate= scanner.readDouble();
sex= scanner.readChar();
age= scanner.readInt();
//Emprec employee = new Emprec(name, address, hours, rate, sex, age);
//grossPay= employee.calc_gross_pay();
//fedTax= employee.calc_fed_tax(employee.getHours(), employee.getRate());
//stateTax= employee.calc_state_tax(employee.getHours(), employee.getRate());
//grossPay= employee.calc_gross_pay();
System.out.println(recNum);
System.out.println(name);
System.out.println(address);
System.out.println(hours);
System.out.println(rate);
System.out.println(sex);
System.out.println(age);
/*
System.out.println(grossPay);
System.out.println(fedTax);
System.out.println(stateTax);
*/
recordNumF.setText(String.valueOf(recNum));
nameF.setText(name);
addressF.setText(address);
hoursF.setText(String.valueOf(hours));
rateF.setText(String.valueOf(rate));
sexF.setText(String.valueOf(sex));
ageF.setText(String.valueOf(age));
//fedF.setText(String.valueOf(fedTax));
//stateF.setText(String.valueOf(stateTax));
//grossF.setText(String.valueOf(grossPay));
} // end try
catch(EOFException eof)
{
closeFile();
eof.toString();
}
catch(IOException io)
{
System.err.println("Error during read from file\n + e.toString()");
System.exit(1);
}
}
i basically followed my professor's example doing this one, i have never seem those errors before. if anyone can tell what might be wrong that would be great. Thanks.