title: Java - NumberFormatException at linear search
body: <p>I am having this issue with the <code>NumberFormatException</code> in my program. Basically, I am asked to read a <code>.csv</code> file separated by <code>;</code> and it looks like this:</p>
  
  <p>// Column Explanation (not in .csv file)</p>
  
  <p>id; Summary; Number; Employee1; Employee2; ....... Employee7;</p>
  
  <pre><code>"1";"Sony";"1600";"Markos";"Nikos";"Antonis";"Nikolas";"Vaggelis";"Markos";"Thanasis";
  "2";"HP";"1000";"Marios";"Dimitra";"Nikolia";"Spiros";"Thomas";"Kostas";"Manolis";
  "3";"Dell";"1100";"Antonis";"Aggelos";"Baggelis";"Nikos";"Kuriakos";"Panagiotis";"Rafail";
  "4";"Acer";"2000";"Marina";"Aggelos";"Spiros";"Marinos";"Xristos";"Antreas";"Basilis";
  </code></pre>
  
  <p>What I have already done is create a String 2-d array or the <code>.csv</code> file called <code>temp_arr</code> and I am asked to write a method that will run a linear search by id and return that company. So here is the thing.</p>
  
  <p>At first, I thought I should convert the input key from int -> String since my <code>temp_arr</code> is a String and compares the strings (which at that time they would be int but read as Strings) using <code>temp_arr[value][value2].equals(string_key)</code>. But I had a <code>NullPointerException</code>.</p>
  
  <p>Then I thought I should better convert my Id's from the <code>temp_arr</code> from String -> Int and then compare with the integer key using <code>==</code> operand. This action returned me a <code>NumberFormatException</code>. </p>
  
  <p>The process is this:</p>
  
  <pre><code>System.out.println("Enter id :");
  Scanner input = new Scanner(System.in); 
  int item = input.nextInt();  // read the key which is an Integer
  int id_int; // temp_arr is String and item is int, must convert ids from String -&gt; int
  for (int i = 0; i &lt; temp_arr.length; i++)
  {
     id_int = Integer.parseInt(temp_arr[i][0]); // Convert from String to int
      if (id_int == item) // If the Array's Id's are == item
      {
        System.out.println(item+" is present at location " + (i+1) );
        break;
      } 
       if (i == temp_arr.length) 
          System.out.println(item + " does not exist");
      }
  </code></pre>
  
  <p><strong>My error appears at line 7</strong> and I do not know why.</p>
  
  <p>Read File process:</p>
  
  <pre><code>String csvFile = "sam.csv"; // .csv file to be placed in the project file!
  BufferedReader br = null; // ini
  String line = "",cvsSplitBy = ";"; // columns asked to be split by ";"
  String[] arr = null;
  String[][] temp_arr = new String[1000][10];
  int temp = 0;
  try
  {
       br = new BufferedReader(new FileReader(csvFile)); //start reading the file
       while ((line = br.readLine()) != null) // while the line has words     
       { 
           arr = line.split(cvsSplitBy); // creating the array
           System.out.println(arr[0] + "\t" + arr[1] + "\t" + arr[2] + "\t" + arr[3] + "\t" + arr[4] + "\t" + arr[5] + "\t" + arr[6] + "\t" + arr[7] + "\t" + arr[8] + "\t" + arr[9] );
        for (int i = 0; i&lt;=9; i++)
        {
             temp_arr[temp][i] = arr[i]; // temp_arr represents (is a copy of) the .csv file
        }
            temp++;
           }
      } catch (FileNotFoundException e) 
      {
         e.printStackTrace();
      } catch (IOException e)
      {
         e.printStackTrace();
      } finally 
      {
        if (br != null)
         {
                  try 
                  {
                      br.close();
                  } catch (IOException e)
                  {
                       e.printStackTrace();
                  }
                   }
              }
     System.out.println("Done!\n");
  </code></pre>
  
  <p>Output (Image) : <img src="https://i.stack.imgur.com/mcWrS.png" alt="Output"></p>
  
  <p>Line 106 which is causing the issue is :
   <code>id_int = Integer.parseInt(temp_arr[i][0]); // Convert from String to int</code></p>