• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getGraphics returnning null pointer exception

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm trying to make a program to display mandelbrot and julia set, i already have the methods to determine weather a point is in the set or not for both, the problem comes when trying to display, my code is this:

My output is as follows :


java.lang.NullPointerException
at Fractales.juliabrot.dibujar(juliabrot.java:146)
at Fractales.juliabrot.calcular(juliabrot.java:110)
at Fractales.juliabrot.<init>(juliabrot.java:25)
at Fractales.Visualizacion.init(Visualizacion.java:25)
at sun.applet.AppletPanel.run(AppletPanel.java:425)
at java.lang.Thread.run(Thread.java:619)
i don't understand why i'm getting null on g, since thats the only reason of why i get npe(well, i don't really understand java very well)
If someone could help me a bit, i'd be really gratefull, thanks in advance.
BTW class visualizacion is only a Japplet that adds the jpanel, this code is not the best around, not even near, but the problem is not in visualizacion, is in where to call getgraphics, or something like that.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't use getGraphics. Instead you should do all painting in the paintComponent method (override it, call super.paintComponent first then your custom code), and call repaint() to trigger a call to this method.

And you shouldn't mix Swing (JPanel) with AWT (Canvas).

Anyway, I'm moving this thread to our GUI forum.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic