Java Velocity Help

Status
This thread has been locked.

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0
Ok. So I am currently learning Java in my free time, and I cant find out whats wrong with my code. When I try making an object move with velX = 1, it doesnt work. I believe its to due with the Tick function, or somthing else, but I dont know how to fix it. Heres my simple code (to most). Please help me :D
 

Attachments

  • Game.zip
    13.2 KB · Views: 19
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Harry

Rustacean
Management
Feedback score
10
Posts
1,606
Reactions
876
Resources
0
Are you getting some sort of error or is it just not working?
 

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0
Are you getting some sort of error or is it just not working?
This is the error message I am getting.

Exception in thread "Thread-0" java.lang.NullPointerException
at com.game.main.Game.tick(Game.java:73)
at com.game.main.Game.run(Game.java:56)
at java.lang.Thread.run(Thread.java:748)
 

Harry

Rustacean
Management
Feedback score
10
Posts
1,606
Reactions
876
Resources
0
This is the error message I am getting.

Exception in thread "Thread-0" java.lang.NullPointerException
at com.game.main.Game.tick(Game.java:73)
at com.game.main.Game.run(Game.java:56)
at java.lang.Thread.run(Thread.java:748)
Yeah, I got that the first time and when I ran it again, it got this (which looks correct):
X: 126584
Y: 200
velX: 1
velY: 0
X: 126485
Y: 100
velX: 1
velY: 0
X: 126585
Y: 200
velX: 1
velY: 0
X: 126486
Y: 100
velX: 1
velY: 0
X: 126586
Y: 200
velX: 1
velY: 0
X: 126487
Y: 100
velX: 1
velY: 0
X: 126587
Y: 200
velX: 1
velY: 0
X: 126488
Y: 100
velX: 1
velY: 0
X: 126588
Y: 200
velX: 1
velY: 0
X: 126489
Y: 100
velX: 1
velY: 0
X: 126589
Y: 200
velX: 1
velY: 0
X: 126490
Y: 100
velX: 1
velY: 0
X: 126590
Y: 200
 

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0
Yeah, I got that the first time and when I ran it again, it got this (which looks correct):
X: 126584
Y: 200
velX: 1
velY: 0
X: 126485
Y: 100
velX: 1
velY: 0
X: 126585
Y: 200
velX: 1
velY: 0
X: 126486
Y: 100
velX: 1
velY: 0
X: 126586
Y: 200
velX: 1
velY: 0
X: 126487
Y: 100
velX: 1
velY: 0
X: 126587
Y: 200
velX: 1
velY: 0
X: 126488
Y: 100
velX: 1
velY: 0
X: 126588
Y: 200
velX: 1
velY: 0
X: 126489
Y: 100
velX: 1
velY: 0
X: 126589
Y: 200
velX: 1
velY: 0
X: 126490
Y: 100
velX: 1
velY: 0
X: 126590
Y: 200
Did you change anything in it? For me it just keeps on saying the error message :/[DOUBLEPOST=1527286205][/DOUBLEPOST]
Did you change anything in it? For me it just keeps on saying the error message :/
Wait.. It says that for me too now, but it doesnt show any color now[DOUBLEPOST=1527286237][/DOUBLEPOST]
Did you change anything in it? For me it just keeps on saying the error message :/[DOUBLEPOST=1527286205][/DOUBLEPOST]
Wait.. It says that for me too now, but it doesnt show any color now
Anddd now it doesnt. ;-;
 
Last edited:

Harry

Rustacean
Management
Feedback score
10
Posts
1,606
Reactions
876
Resources
0
Did you change anything in it? For me it just keeps on saying the error message :/[DOUBLEPOST=1527286205][/DOUBLEPOST]
Wait.. It says that for me too now, but it doesnt show any color now[DOUBLEPOST=1527286237][/DOUBLEPOST]
Anddd now it doesnt. ;-;
Ah, I see what has happened. You're trying to start the game before you've initialised handler. This means that at the very first tick, the handler is null and so, you get a null exception (I believe).

Edit: Yep, just swap them around.

Screen Shot 2018-05-25 at 23.12.26.jpg
 

Attachments

  • Screen Shot 2018-05-25 at 23.12.26.jpg
    Screen Shot 2018-05-25 at 23.12.26.jpg
    28.6 KB · Views: 87

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0
Ah, I see what has happened. You're trying to start the game before you've initialised handler. This means that at the very first tick, the handler is null and so, you get a null exception (I believe).

Edit: Yep, just swap them around.

View attachment 128813
So.. Switch the two?[DOUBLEPOST=1527286589][/DOUBLEPOST]
Ah, I see what has happened. You're trying to start the game before you've initialised handler. This means that at the very first tick, the handler is null and so, you get a null exception (I believe).

Edit: Yep, just swap them around.

View attachment 128813
Okay, so thats working now, But the setcolor isnt working now.. It should be setting the whole thing to black and having two white squares in it..
 
Last edited:

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0
Yep, works for me. This means that you start the game after the handler has been initialised and so, no null exception should occur.
Yeah it works now, just the colors for me dont.. :p I said above ^^[DOUBLEPOST=1527287772][/DOUBLEPOST]
Yep, works for me. This means that you start the game after the handler has been initialised and so, no null exception should occur.
Do you know or have any clue as to how to make the colors work too?
 
Last edited:

Harry

Rustacean
Management
Feedback score
10
Posts
1,606
Reactions
876
Resources
0
Yeah it works now, just the colors for me dont.. :p I said above ^^[DOUBLEPOST=1527287772][/DOUBLEPOST]
Do you know or have any clue as to how to make the colors work too?
Had a quick look but couldn't see the problem. I will have a look tomorrow if you haven't solved it by then.
 

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0
Had a quick look but couldn't see the problem. I will have a look tomorrow if you haven't solved it by then.
Alright :p I honestly cant find it xD
 

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0

DanTheDonut

Config Specialist | Setups | Donut Eater
Premium
Feedback score
8
Posts
143
Reactions
21
Resources
0
Code:
@Override
public void paintComponent(Graphics g) {
    // code
}
Thanks, but I had made it work by lowering the tick speed.
 
Status
This thread has been locked.
Top