In this code, I create a scanner to read a file full of ASCII values, which are ints. I put them in a 2d array of chars using nested loops after I typecast them to type 'char', and then proceed to print the resulting arrays in a separate method. the result is supposed to be an image of Homer Simpson from the Simpsons cartoon made out of characters, but an InputMismatchException prevents the image from coming to life, and I really struggle to see where I am trying to accept an integer that doesn't match what type it is. I assume it is in the nested loops, but after tweaking all that I can, I still cannot find the underlying problem. I would appreciate any help.
import java.util.*;
public class HomerSimpson
{
public static void main(String[] args)
{
display();
}
public static void display()
{
Scanner fileReader = new Scanner("homer.txt");
char[][] homer = new char[fileReader.nextInt()][fileReader.nextInt()];
for (int i = 0; i < homer.length; i++)
{
for (int j = 0; j < homer[0].length; j++)
{
homer[i][j] = (char)fileReader.nextInt();
}
}
print2DArray(homer);
}
public static void print2DArray(char[][] homer)
{
for (int h = 0; h < homer.length; h++)
{
System.out.println(Arrays.toString(homer[h]));
}
}
}