Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are trying to add more items to your array than your array has space for, try using a List like <a href="http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html" rel="nofollow">java.util.ArrayList</a>. </p> <p>Also the file shows a list of names, then a list of numbers, then a list of letters, then a list of decimals, but in your code, you read in a name, then a number, then a letter, then a double. </p> <p>Try something like</p> <pre><code>import java.util.ArrayList; import java.io.File; public class Prog5Methods{ public void foo(String filename){ ArrayList&lt;String&gt; names=new ArrayList&lt;String&gt;(); ArrayList&lt;Integer&gt; ints=new ArrayList&lt;Integer&gt;(); ArrayList&lt;Character&gt; chars=new ArrayList&lt;Character&gt;(); ArrayList&lt;Double&gt; dubs=new ArrayList&lt;Double&gt;(); ReadFromFile(new Scanner(new File(filename)),names,ints,chars,dubs); } public void ReadFromFile(Scanner input, ArrayList&lt;String&gt; names, ArrayList&lt;Integer&gt; numbers, ArrayList&lt;Character&gt; letters, ArrayList&lt;Double&gt; num2){ System.out.println("\nReading from a file...\n"); while(input.hasNext()&amp;&amp;!input.hasNextInt()){ names.add(input.next()); } while(input.hasNextInt()){ numbers.add(input.nextInt()); } while(input.hasNext()&amp;&amp;!input.hasNextDouble()){ letters.add(input.next().charAt(0)); } while(input.hasNextDouble()){ num2.add(input.nextDouble()); } System.out.println("\nDONE\n"); } public String[] convertToArray(ArrayList&lt;String&gt; arr){ String[] ans=new String[arr.size()]; arr.toArray(ans); return ans; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload