java - NullPointerException while reading txt file -


below part of program i've written iterate through file find , compare 2 seperate numbers.

it searches each line start point line equal "[device|sensors|checksum]". looks first , second occurrences of "value", gets hex number on line, converts type long. if these 2 long numbers equal we're good, otherwise report problem

here's extract of file i'm using

address(18) = 0x0053 page(18) = sensor value(19) = 0x1 desc(19) = used bytes high priority task address(19) = 0x0053 byte_no(19) = 2 page(19) = sensor ;end of section [device|sensors|stack] [device|sensors|checksum] address(18) = 0x0053 page(18) = sensor value(2) = 0xe0a64f36 address(18) = 0x0053 page(18) = sensor default(19) = 0x00 value(3) = 0xe0a64f36 page(18) = sensor desc(19) = used bytes high priority task ;end of section [device|sensors|checksum] 

i cannot find wrong code despite trying debug already. loops i've used seem sound.

try {   {//read line check if line "[device|sensors|checksum]" while line isn't ";end of section [device|sensors|checksum]"                        line = reader.readline();//reads lines "[device|sensors|checksum]"    if (line.equals("[device|sensors|checksum]")) { //if line "[device|sensors|checksum]"                                                     //(check if line "value") else read next line                        {// read line , (check if line "value") while line doesn't contain "value"       line = reader.readline();//reads line first "value"       if (line.contains("value")) { // if line "value" retrieve necessary value                                    // else read next line        hex1 = line.split("=")[1].trim();       l1 = long.parselong(hex1.substring(2), 16);       jframe frame1 = new jframe("joptionpane showmessagedialog example");       joptionpane.showmessagedialog(frame1, "value has hex number\n " + hex1 + "\n\n , integer\n" + l1 + "\n");        system.out.println("here's line read  " + line);       system.out.println("here's hex number line  " + hex1);       system.out.println("here's integer hex number  " + l1 + "\n");        break;      }     } while (!"value".contains(line = reader.readline()));//while2       line = reader.readline();  //reads line after first "value" has been found      {//  read line , check if line has "value" while line doesn't contain "value"       line = reader.readline();//reads lines second "value"       if (line.contains("value")) { // if line "value" retrieve necessary value                                    // else read next line        hex2 = line.split("=")[1].trim();       l2 = long.parselong(hex2.substring(2), 16);       jframe frame2 = new jframe("joptionpane showmessagedialog example");       joptionpane.showmessagedialog(frame2, "value has hex number\n " + hex2 + "\n\n , integer\n" + l2 + "\n");        system.out.println("here's line read  " + line);       system.out.println("here's hex number line  " + hex2);       system.out.println("here's integer hex number  " + l2 + "\n");        break;       }     } while (!"value".contains(line = reader.readline()));    }   } while (!";end of section [device|sensors|checksum]".equals(line = reader.readline()));   if (l1 == l2) {    joptionpane.showmessagedialog(null, "both checksum values equal!");    int status1 = 0;    system.exit(status1);  } else {     joptionpane.showmessagedialog(null, "both checksum values not equal");     int status2 = 0;     system.exit(status2);   }  } catch (ioexception e) {    system.out.println("io exception. not read file!"); } 

edit

the output , stack trace npe

run: here's line read  value(2) = 0xe0a64f36 here's hex number line  0xe0a64f36 here's integer hex number  3768995638  exception in thread "main" java.lang.nullpointerexception @ robertskostalproject.checksumfinder.hexfinder(checksumfinder.java:32) @ robertskostalproject.checksumgui.askdirectory(checksumgui.java:43) @ robertskostalproject.robertskostalproject.main(robertskostalproject.java:18) build stopped (total time: 11 seconds) 

since haven't specified where "in 2nd while loop" npe, i'll quote bufferedreader#readline():

returns: string containing contents of line, not including line-termination characters, or null if end of stream has been reached

additionally, you're using frame2 variable haven't seen initialized.