When I drawn image got NullPointerException
i want to draw a image locate on a jpanel, but every time when i use drawImage, it got Exception in thread "main" java.lang.NullPointerException
at PokerGUI.<init>(PokerGUI.java:45)
at PokerGUI.main(PokerGUI.java:107)
here is my code:
import java.awt.*;
import javax.swing.*;
import java.awt.Toolkit;
class PokerGUI extends JFrame
{
JPanel TablePanel = new JPanel();
JPanel ButtonPanel = new JPanel();
Color color = new Color(40,160,40);
String[] picRank = {"a","2","3","4","5","6","7","8","9","t","j","q","k"};
String[] picSuit = {"h","d","s","c"};
Image img;
String file;
public PokerGUI()
{
super();
setTitle("Poker Client");
Container container = getContentPane();
container.setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
file = picRank[1]+picSuit[3]+".gif";
/*Image bg = new ImageIcon(file).getImage();*/
this.getGraphics().drawImage(getPokerImage(file), 0, 0, null);
Button CheckButton = new Button("Check");
Button FoldButton = new Button("Fold");
Button RaiseButton = new Button("Raise");
Button CallButton = new Button("Call");
ButtonPanel.add(CheckButton);
ButtonPanel.add(FoldButton);
ButtonPanel.add(RaiseButton);
ButtonPanel.add(CallButton);
TablePanel.setBackground(color);
container.add(TablePanel, BorderLayout.CENTER);
container.add(ButtonPanel, BorderLayout.SOUTH);
this.setSize(800, 600);
this.setVisible(true);
}
protected void makebutton(Button button, GridBagLayout gridbag, GridBagConstraints c)
{
gridbag.setConstraints(button, c);
add(button);
}
public static void main(String[] args)
{
new PokerGUI();
}
public void paint(Graphics g)
{
super.paint(g);
if(img != null)
g.drawImage(img,0,0,getWidth(),getHeight(),null);
}
public Image getPokerImage(String file)
{
return Toolkit.getDefaultToolkit().getImage(file);
}
}
Any help would be appreciated

