title: java.util.ArrayList cannot be cast to [Ljava.lang.Object
body: <p>Was pulling my hair out of this ! There are two data in text file. I trying to retrieve them out but I get below errors</p>
  
  <pre><code>##########  Error with java.lang.ClassCastException: java.util.ArrayList cannot be cast to [Ljava.lang.Object;  ##########
  Size 1
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code> try {
          File file = new File(filePath + "ABC.txt");
          BufferedReader br = new BufferedReader(new FileReader(file));
          String st;
          List list = new ArrayList();
  
          try {
              while ((st = br.readLine()) != null) {
                  String id = st.substring(92, 100);
                  try {
                      list.add(getDetail(id));
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  for (Object[] o : (List&lt;Object[]&gt;) list) {
                      Details x = new Details();
                      x.setType(o[0].toString());
                       ....
                  }
              }
  
              br.close();
  
          } catch (Exception ex) {
              logger.printError(Reader.class, "Error with " + ex);
          }
          logger.printInfo(Reader.class, "Size " + list.size());
  
      } catch (IOException ex) {
          ex.printStackTrace();
      }
  </code></pre>
  
  <p><strong>Query</strong></p>
  
  <pre><code>public List getDetail(int id){
          StringBuilder bf = new StringBuilder();
           bf.append("SELECT ");
           bf.append("'ABC', ");
                  ....
          return em.createQuery(bf.toString()) .getResultList();
      }
  </code></pre>
  
  <p>Been stucked at here for more than 1 hour. Any help or advise would be much appreciated. </p>