• Post Reply Bookmark Topic Watch Topic
  • New Topic

null pointer exception  RSS feed

 
Preethi sakar
Greenhorn
Posts: 19
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am try to move circle.Below is my code...



and i have error

run:
Exception in thread "main" java.lang.NullPointerException
at swingdesing.Game.buffer(Game.java:32)
at swingdesing.Game.moveBall(Game.java:27)
at swingdesing.Game.main(Game.java:51)
BUILD SUCCESSFUL (total time: 9 seconds)

how to overcome this??
Thanks in advance
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the real line numbers; your code has got different line numbers from the original.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it might be the BufferStrategy you never seem to use, and have set to null. Try removing all mention of that bf reference.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you are using the BufferStrategy after all. Why are you not drawing in the paintComponent method?
 
Preethi sakar
Greenhorn
Posts: 19
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Please post the real line numbers; your code has got different line numbers from the original.


error line is 20 25 and 42
 
Preethi sakar
Greenhorn
Posts: 19
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I see you are using the BufferStrategy after all. Why are you not drawing in the paintComponent method?


Please explain me the usage of BufferStrategy

Thanks for quick reply
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at this snippet from your code



on line 2 here, you explicitly set bf to "null". The, on line 4, you try and call a method on a null reference. Hence the NPE.

You do not have a BufferStrategy object, so you can't call its methods.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preethi sakar wrote: . . . Please explain me the usage of BufferStrategy . . .
Don't know. Why not simply use the paintComponent() method and cast the Graphics object inside that method?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!