We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys,
Based on what i understand, NullPointerException error is happening when some value is not initialize yet and we try to call it in a function. But looking at my code, I tried to re-initialize the values in NullPointerException error line but it seems that the error are still there. Can anyone help me with this?
Answers
sure...
sometimes multiple values in one line can be suspicious candidates, maybe you're looking at the wrong one?
in the line before your error line say
or post your code....
I see
which line holds the error?
can i give u a link to my code? it kinda long
https://www.dropbox.com/s/6zp8xi91m0dfwj7/pooooooooooool.zip?dl=0
in
float distance = dist(ballPos.x, ballPos.y, tempBall.ballPos.x, tempBall.ballPos.y);
this is your problem:
tempBall.ballPos
tempBall itself is ok though
since tempBall is coming from table.b_arr[i]; make sure tempBall.ballPos is set there
the same error come out when i tried to set it up
is that your code??
you cannot just reset it there!!!
but i set it in my Ball class. i have no idea where should i reset it. im really new with computing, im sorry
ok, several issues
first
first don't call
repel
in the constructor of class Ball (line 35) !!!!!!!2nd
2nd in
class Table
you say16 balls, ok, but in
get_array_ball
you define only 14 balls, so it crashes with number 15 (say 14 inclass Table
)at the moment, everywhere it says
< table.b_arr.length
in a for-loop it will crashi editted the array size to 14.
so, where should i call it? actually, i modify the code from this pde file,
https://www.openprocessing.org/sketch/126036
to make it fit my program. i just change the array and the object in the array. in that code, they call repel in the class Ball.
yeah, it works in the original code because they use an arrayList instead of a fixed array as you have
just don't call repel at all for now.
(Repel has the function to make sure that the balls don't overlap each other in the beginning. Not important.)
okay, i got it. thanks mate. appreciate your help a lot. now i can proceed with it. :D