Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Creating a picture in java out of a txt file containing 0's and 1's

    I need to make a 2D array out of the 0's and 1's in the file. The file is 25X25 in total so contains 625 characters in all, either 0 or 1.

    This is the code I have so far:


    import london.*;
    public class Picture {
    public static void main (String[] arg) {
    EasyReader fileInput = new EasyReader("picture.txt");
    EasyGraphics g = new EasyGraphics(30,30);

    int cols = 30; // How many columns the array should have
    int rows = 30; // How many rows the array should have

    int[][] array2d = new int[rows][cols];

    String strLine;
    int xCounter = 0;
    // Reading lines from the file using EasyReader
    while ((strLine = fileInput.readLine()) != null) // fileInput.readLine() fills the variable strLine with a String value.
    {
    char[] stringArray= new char[42];
    stringArray = strLine.toCharArray();
    //display the array
    for(int index=0; index < stringArray.length; index++) {
    array2d[xcounter][index] = (int) stringArray[index] - 0x30;
    }
    xCounter++;
    }
    }
    }


    The EasyReader is just a class for input that inherits the BufferedReader class and is part of the "london" package. There is 1 error in compilation which says:


    Picture.java:21: cannot find symbol
    symbol : variable xcounter
    location: class Picture
    array2d[xcounter][index] = (int) stringArray[index] - 0x30;
    ^


    Please can someone help me, I am literally pulling my hair out at this!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Jar file making - picture problem
    By amman in forum New To Java
    Replies: 3
    Last Post: 05-06-2011, 12:14 PM
  2. Creating a file is Holding up java.
    By rizowski in forum New To Java
    Replies: 0
    Last Post: 04-20-2011, 05:47 PM
  3. Picture not showing when create JAR file
    By kmckinley820 in forum New To Java
    Replies: 4
    Last Post: 03-19-2011, 10:11 PM
  4. Replies: 1
    Last Post: 10-22-2008, 05:02 PM
  5. Print a picture file
    By oli001 in forum New To Java
    Replies: 0
    Last Post: 11-26-2007, 01:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •