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

    Default Making a java picture

    I have the following code for making a 2D array out of a txt file (which contains 0's and 1's) to make a picture where the 0's are background and the 1's a green dot.
    the import statement is to a package "london" which contains 2 classes for input (EasyReader) and graphics (this makes a graphics window of custom size), (EasyGraphics):

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

    int cols = 25;
    int rows = 25;

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

    int xCounter = 0;

    char[] stringArray;

    for(int index=0; index < stringArray.length; index++) {
    }

    xCounter++;

    }
    }

    However during compile there is 1 error pointing to the "for(int index=0; index < stringArray.length; index++) {" line which says "variable stringArray might not have been initialized"?! Does anyone know what this means and how to solve it?!

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Making a java picture

    That error is pretty much self-explanatory. Your variable stringArray is never initialized, so it doesn't have a value, so you can't use it.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Join Date
    Nov 2011
    Posts
    11
    Rep Power
    0

    Default Re: Making a java picture

    OK cheers! Would you know how I could initialise it and what to?!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default Re: Making a java picture

    Quote Originally Posted by The Dark Dragon View Post
    OK cheers! Would you know how I could initialise it and what to?!
    Without any other information from you, the following will do fine:

    Java Code:
    char[] stringArray= new char[42];
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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. Java Picture Frame ???
    By shqiptari in forum New To Java
    Replies: 0
    Last Post: 03-30-2011, 12:02 AM
  3. How to create a network picture Using Java
    By nidhirastogi in forum AWT / Swing
    Replies: 0
    Last Post: 02-16-2011, 04:54 PM
  4. Trying to get a picture drawn on java
    By thorobred in forum New To Java
    Replies: 2
    Last Post: 02-10-2011, 03:03 AM
  5. Making a picture Warhol Style
    By chick in forum New To Java
    Replies: 4
    Last Post: 04-13-2010, 09:08 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
  •