I am having another problem with NullPointerException. This time it is highlighting tellen = telno.length()
. Beore you ask:
- There is data in the text file to be read to that variable.
- All variables were initialized.
- Buffered Reader is also initialized.
Here is a snippet of my code:
while((telno = br.readLine()) != null){ name = br.readLine(); surname = br.readLine(); company = br.readLine(); house = br.readLine(); street = br.readLine(); locality = br.readLine(); postcode = br.readLine(); telno = br.readLine(); tellen = telno.length(); mobno = br.readLine(); sep = br.readLine(); if(tellenx > tellen) tellen = tellenx; }
Please help. Thanks. Text file:
- Name
- Surname
- Company
- House
- Street
- Locality
- Telephone number
- Mobile Number
Problem is in the telephone (tellen) All these names are fictional, and this program is a telephone directory
George
Farrugia
Some Company
9, Flowers
Quail Street
Bubaqra
BBQ 1569
21369854
79825643
--------------------------------------------
Paul
Zammit
9
Bird Street
St. Julians
STJ 0000
21545796
79745247
--------------------------------------------
Peter
Spiteri
Oak Company
Trees
Birch Street
Oakgrove
TRE 3333
21323323
99323323
--------------------------------------------
The blank after Zammit
is a space. That is placed if there is no data to avoid a problem like this.