|
-
NullPointerException when reading text file
I'm trying to teach myself Java and I'm having a problem reading from a random
access file. There is too much code to paste here so hopefully the limited
amount I supply will be enough. What I'm trying to do is read all the records
from the file and display them in a TextArea. The problem is when I try
to get the data from the class I get a NullPointerException. I'm not sure
why since I create a new version of the class. Thanks for you help in advance.
private void readRecords()
{
Record record = new Record();
DecimalFormat twoDigits = new DecimalFormat( "0.00" );
try{
recordDisplay.setText("The records are:\n");
while(true){
record.read(file);
record = (Record) input.readObject();
if (String.valueOf(record.getRecord()) == " ")
{
recordDisplay.append(record.getRecord() +
"\t" +
record.getTool() +
"\t" +
record.getQuantity() +
"\t" +
record.getCost() +
"\n");
}
}
}
catch(EOFException eofex)
{
//do nothing
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,
"Error " + e,
"Error",
JOptionPane.ERROR_MESSAGE );
}
}//end readRecords
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks