java - Null Pointer Exception Occurs only while comparison and not printing out values -


        public static void main(string[] args) throws filenotfoundexception, ioexception {     // todo code application logic here     bufferedreader in1 = new bufferedreader(new filereader("595231gov_nov_13_assessed.txt"));     bufferedreader in2 = new bufferedreader(new filereader("627231farsidetect.txt"));         string id = null;       int count = 0;      string count_line=null;       while((count_line = in1.readline()) != null){           if(count_line.contains("id: "))               count ++;       }       system.out.println(count);       file1 [] file_1 = new file1[count];       in1 = new bufferedreader(new filereader("595231gov_nov_13_assessed.txt"));          int = 0;      string line = null;      string relation = null;      while ((line = in1.readline()) != null && != count){          if(line.contains("id:")){              file_1 [i] = new file1();              file_1[i].id = line;          }          else if(line.contains("relation:")){              file_1[i].relation = line;          }          else if(line.contains("result:")){              file_1[i].result = line;              ++;          }          else if(line.contains("tp") || line.contains("fp") || line.contains("tn") || line.contains("fn")){              file_1[i-1].comment = line;          }       }       line = null;     relation = null;         =0;       int count2 = 0;      count_line=null;       while((count_line = in2.readline()) != null){           if(count_line.contains("id: "))               count2 ++;       }       system.out.println(count2);       in2 = new bufferedreader(new filereader("/home/627231farsidetect.txt"));       file2 [] file_2 = new file2[count2];       while ((line = in2.readline()) != null && != count2){          if(line.contains("id:")){              file_2 [i] = new file2();              file_2[i].id = line;          }          else if(line.contains("relation:")){              file_2[i].relation = line;          }          else if(line.contains("result:")){              file_2[i].result = line;              ++;          }       }       in1.close();     in2.close();      (i=0; i<file_1.length - 1; i++)     {         system.out.println(file_1[i].id);         system.out.println(file_1[i].relation);         system.out.println(file_1[i].result);         if(file_1[i].comment != null)             system.out.println(file_1[i].comment);     }        (i=0; i<file_2.length; i++)     {         system.out.println(file_2[i].id);         system.out.println(file_2[i].relation);         system.out.println(file_2[i].result);     }          (i = 0; < file_1.length-1; i++){         for(int j=0;j< file_2.length; i++){             if(file_1[i].id != null && file_2[j].id != null && file_1[i].relation != null && file_2[j].relation !=null){             if(file_1[i].id.equals(file_2[j].id) && file_1[i].relation.equals(file_2[j].relation)){                 if(!(file_1[i].result.equals(file_2[j].result))){                     system.out.println(file_1[i].id);                     system.out.println(file_1[i].relation);                     system.out.println(file_1[i].result);                     if(file_1[i].comment != null)                         system.out.println(file_1[i].comment);                 }             }         }     }     }    }  public static class file1{ public string id; public string relation; public string result; public string comment;         public file1() {         this.result = null;         this.id=null;         this.relation = null;         this.comment = null;     } }  public static class file2{ public string id; public string relation; public string result;      public file2() {         this.result = null;         this.id=null;         this.relation = null;     }  } 

-when printout values, not face null pointer exception, -but when try , comparison faced null pointer exception , can't figure out why. -netbeans points comparison statement

if(file_1[i].id.equals(file_2[j].id) && file_1[i].relation.equals(file_2[j].relation)) 

something else unusual that, have assigned values file_1 until file_1[length] prints out length - 1 values. whereas assigned values file_2 same way , prints fine. please help. processing farsi text, there might possibility of weird characters, pretty sure there has index values.

don't know if intentional or not, in loop seem incrementing wrong value (i instead of j)...

for (i = 0; < file_1.length-1; i++) {    for(int j=0;j< file_2.length; j++)    {       if(file_1[i].id != null && file_2[j].id != null && file_1[i].relation != null && file_2[j].relation !=null)       {          if(file_1[i].id.equals(file_2[j].id) && file_1[i].relation.equals(file_2[j].relation))          {             if(!(file_1[i].result.equals(file_2[j].result)))             {                system.out.println(file_1[i].id);                system.out.println(file_1[i].relation);                system.out.println(file_1[i].result);                if(file_1[i].comment != null)                   system.out.println(file_1[i].comment);             }          }       }    } } 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -