0
Can anyone help me with how to draw line in java
import java.awt.Graphics; import java.awt.Color; class Dcoder { public void paint(Graphics g) { g.drawLine(0,480,960,480); } public static void main(String args[]) { Dcoder ob=new Dcoder(); ob.paint(null); } } output- Exception in thread "main" java.lang.NullPointerException at Dcoder.paint(source.java:7) at Dcoder.main(source.java:12) take Dcoder as line and if possible plz tell what's the problem is
1 ответ
+ 2
Judging from the surface, you passed null into paint(), and hence you invoked drawLine() using a null pointer.
I have no idea how awt graphics are supposed to work, but you can try:
ob.paint(new Graphics());