Help!

Posted by (twitter: @jFransham)
December 17th, 2011 2:39 am

I’m using java array literals for my levels (bad form, I know, but I’m pressed for time and want to have as much time as possible creating content) but it keeps saying my arrays are null. This is the offending code:

protected Integer[][] rawLevel = 
		{
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
		};
Any help with this would be greatly appreciated

7 Responses to “Help!”

  1. gavin5564 says:

    Not sure what language you are using but perhaps declare a new int array then initialize it in a constructor..

  2. dertom says:

    Well, that should work! Can you pastbin you code?

  3. The Jahn says:

    I don’t think you can define 2D Arrays using literals in Java. Not without specifying the first dimension, anyway.

    protected int[][] rawLevel = new int[4][]{
    new int[]{0,0,0,0},
    new int[]{0,0,0,0},
    new int[]{0,0,0,0},
    new int[]{0,0,0,0}
    };

    You might be better off using a single array of strings. It’s a lot easier to work with – and under the hood it’s pretty much just an array of ints (representing ASCII).

    protected String[] rawLevel = new String[]{
    “….”,
    “….”,
    “….”,
    “____”
    };

    ^ Something like that

  4. The Jahn says:

    … I see I’m not the only one procrastinating.

  5. Jack says:

    @The Jahn you can define 2D Arrays with literals, I did it in my warmup game and there were no problems whatsoever. I’ll try out the string idea, thanks

    @gavin5564 java, and I could do that but it would mean setting each and every block independantly, at least with this I can get an idea of how it’s going to look

  6. Jack says:

    and it’s STILL returning null! the sheer amount of irritation I’m feeling right now is beyond mere words

  7. Jack says:

    ah, found out what it was. I was declaring it in the class, but calling the function that needs it from the superclass’ constructor, so it didn’t set it before trying to read it

Leave a Reply

You must be logged in to post a comment.

[cache: storing page]