• Post Reply Bookmark Topic Watch Topic
  • New Topic

getGraphics returnning null pointer exception

 
omar nunez
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!