maybe myToolkit.getImage is returning a null,to make sure, type this:
System.out.println("ruler="+ruler);
but dont write ruler.toString(), cos if ruler is null, then its like
typing :
null.toString()
and then passing null (ruler) to g.drawImage(null),,,,,,, will throw
an exception!
so the solution is , put
if(ruler==null)
{
//doAlternativeActionOrPicture();
}
else
{ Graphics g = jPanel2.getGraphics();
g.drawImage(ruler, 0, 0, jPanel2);
}