Reputation: 89
When I'm trying to draw a polygon I get a NullPointerException
.
This is how I am trying to do it:
Roi roi = imp.getRoi();
Polygon p = roi.getPolygon();
Graphics g=null;
g.drawPolygon(p.xpoints, p.ypoints, p.npoints);
Please suggest how I can fix this.
Upvotes: 0
Views: 184
Reputation: 285460
You're not using the right Graphics object. This should be done in a JComponent's paintComponent(...)
method, and you should use the Graphics object passed in by the JVM. Either that or draw this in a BufferedImage using a Graphics2D object obtained from it via createGraphics()
.
Regarding your edit: yikes!
This is guaranteed to throw a NPE every time.
Bar bar = null
bar.someMethod();
Upvotes: 1