Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException when porting game over to Android
    primarykey
    data
    text
    <p>I am working on porting over a Java Maze application into Android. What this means is that I am taking the Java code given to me (I did not write this part), rewriting some of the classes (i.e. Changing the Java graphics into Android graphics so that it works on Android, and I creating Android UI activities (which I have completed).</p> <p>When I run my program I get a NullPointerException that complains about the following line being the cause of the exception: </p> <pre><code>maze.newMaze(root, cells, dists, startx, starty); </code></pre> <p>This is the error:</p> <pre><code>01-19 19:22:53.157: E/AndroidRuntime(638): FATAL EXCEPTION: Thread-79 01-19 19:22:53.157: E/AndroidRuntime(638): java.lang.NullPointerException 01-19 19:22:53.157: E/AndroidRuntime(638): at falstad.MazeBuilder.run(MazeBuilder.java:729) 01-19 19:22:53.157: E/AndroidRuntime(638): at java.lang.Thread.run(Thread.java:856) </code></pre> <p>The line of error is in MazeBuilder's run method obviously and I figured out that 'maze' is null and the parameters are valid. I also figured out that maze is set to null in Mazebuilder's build method...which passes through a Maze object and sets maze = mz (maze). </p> <p>So I find in Maze.java where mazebuilder.build(...) is called and it is in the method maze.build() AT THE BOTTOM with 'this' as the parameter: </p> <pre><code> /** * Method obtains a new Mazebuilder and has it compute new maze, * it is only used in keyDown() * @param skill level determines the width, height and number of rooms for the new maze */ private void build(int skill) { // switch screen state = STATE_GENERATING; redraw(); // select generation method switch(method){ case 1 : mazebuilder = new MazeBuilderPrim(); // generate with Prim's algorithm break ; case 0: // generate with Falstad's original algorithm (0 and default), note the missing break statement default : mazebuilder = new MazeBuilder(); break ; } // adjust settings and launch generation in a separate thread mazew = skill_x[skill]; mazeh = skill_y[skill]; int roomcount = skill_rooms[skill]; mazebuilder.build(this, mazew, mazeh, roomcount, skill_partct[skill]); // mazebuilder calls back by calling newMaze() to return newly generated maze } </code></pre> <p>Reading this tells me that the parameter 'this' is null. I have read about "this" function in java and dont understand it still, so I'm not sure why it's null. I'm also guessing part of the problem is that because I have</p> <pre><code>mazebuilder = new MazeBuilder() </code></pre> <p>and not </p> <pre><code>mazebuilder = new MazeBuilder(this) </code></pre> <p>When I try adding 'this' parameter (like above code line), it squawks at me about constructor MazeBuilder(Maze) being undefined. But my GeneratingActivity GA is a different type than Maze maze...so clearly I can't create a constructor that sets GA = maze...I'm confused. </p> <p>Again, I very much appreciate any help and patience. This has been a nightmare for a newbie. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload