multithreading - Java nullpointerexception for a 2D scrolling game -


i'm making game, 2d side scrolling, kinda terraria. in game, have offsets, xoff , yoff, , move terrain. have method character, move(), , this:

public void move() {         if (!abletomove) //makes sure can move             return;         // x += movex; these 2 methods work, x , y player coords.         // y += movey;         core.setyoff(1); //core main class, global variables stored     } 

the comments label , describe each variable. so, setyoff(1) sets yoff so:

private void setyoff(int i){      yoff += i; } 

now, there 1 way accessing move method. in thread, called playerthread, have constant call move() , method called applygravity(), doesnt have relevance question. in playerthread.

now here problem i'm having... when call setyoff(), i'm getting following error:

exception in thread "player thread" java.lang.nullpointerexception     @ main.player.move(player.java:33)     @ main.playerthread.run(playerthread.java:24)     @ java.lang.thread.run(unknown source) 

which telling me when i'm calling setyoff() method in move() method, doesnt work. i've tried testing , moving call set y offset thread itself, , gives same error... tried move refreshthread, , interestingly did work... moved entire map down 1 pixel every 20 milliseconds... , have no clue why! wrong move method makes not work, or better yet, playerthread, isnt making work in long run? different refreshthread? if guys need entire code involving calls, creation, , such of each thread, can provide that, i'm not sure need that... need differently? in advance!

edit: tried, in playerthread commenting out move() call, , having adjust y offset, , worked! has move method, again, why?

correction previous edit: testing more, put move() call thread, , kept setyoff(1) in it, , still worked, again not within move method itself...

the nullpointerexception indicates object on method being called null, in case, core object. fix , problem should go away.


Comments

Popular posts from this blog

php - Dynamic url re-writing using htaccess -

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -