Question: Hi im trying to add the arraylist (tempr) into a String array but im getting this error WorldGameShell.java:44: error: incompatible types: Object[] cannot be
Hi im trying to add the arraylist (tempr) into a String array but im getting this error " WorldGameShell.java:44: error: incompatible types: Object[] cannot be converted to String[]. the bold code line is where the problem is.
public static void fillArray(String[] correct, String[] incorrect) throws FileNotFoundException
{
File file1 = new File("correct.txt"); File file2 = new File("incorrect.txt"); Scanner Sc = new Scanner(file1); Scanner Sc2 = new Scanner(file2); String temp = "";
List tempr = new ArrayList(); while (Sc.hasNextLine()) { temp=Sc.nextLine(); tempr.add(temp); } correct = tempr.toArray(new String[0]);
while (Sc2.hasNextLine()) { temp=Sc2.next(); tempr.add(temp); } incorrect = tempr.toArray(new String[0]);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
