title: Why do I get an ArrayStoreException in Java?
body: <p>My question is, why do I get an Exception in thread "main" java.lang.ArrayStoreException :</p>
  
  <blockquote>
    <p>at java.lang.System.arraycopy (native method)
    at java.util.ArrayList.toArray (unknown source)
    at Main.main (Main.java:50)</p>
  </blockquote>
  
  <p>Here's my code :</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class Main {
  
  static public boolean readPinsData(File dataFile, ArrayList&lt;Integer&gt; data) {
     boolean err = false;
     try {
        Scanner scanner = new Scanner(dataFile);
        String line;
        while (scanner.hasNext()) {
           line = scanner.nextLine();
           try {
              data.add(Integer.parseInt(line));
           } catch (NumberFormatException e) {
              e.printStackTrace();
              err = true;
           }
        }
        scanner.close();
     } catch (FileNotFoundException e) {
        e.printStackTrace();
        err = true;
     }
  
     return err;
  }
  
  
  public static void main(String[] args) {
      Console console = System.console();
      int pinSize = 0;
  
      do{
      char passwordArray[] = console.readPassword("Enter pin: ");
      pinSize = passwordArray.length;
  
      if(pinSize != 4){
              System.out.println("Pin must be 4 digits");
          } else {
              System.out.println("Checking...");
          }
  
  
      ArrayList&lt;Integer&gt; pins = new ArrayList&lt;Integer&gt;();
     readPinsData(new File("bdd.txt"), pins);
     //System.out.println(pins);
     //System.out.println(passwordArray);
  
     String[] thePins = pins.toArray(new String[pins.size()]);
     String passEntered = String.valueOf(passwordArray);
     int i = 0;
  
     for(i = 0 ; i &lt; thePins.length ; i++){
        if(passEntered == thePins[i]){
            System.out.println(":)");
        }else{
            System.out.println(":(");
        }
    }
  
     }while(pinSize != 4);
  
  }
  }
  </code></pre>
  
  <p>My bdd.txt file looks like :</p>
  
  <pre><code>1111
  2222
  3333
  4444
  5555
  6666
  7777
  8888
  9999
  </code></pre>