Display display = null;
String url = "http://188.2.222.253/screenshot.png";
DataInputStream is = null;
Image img= null;
try
{
HttpConnection c = (HttpConnection) Connector.open(url);
int len = (int)c.getLength();
if (len > 0)
{
is = c.openDataInputStream();
byte[] data = new byte[len];
is.readFully(data);
img = Image.createImage(data, 0, len);
Form f = new Form("Image");
GameCanvas gc = null;
Graphics g = null;
g.drawImage(img, 0, 0, 0); //NullPointerException
gc.paint(g);
display.setCurrent(gc);
}
else
{
showAlert("length is null");
}
is.close();
c.close();
}
catch (Exception e)
{
e.printStackTrace();
showAlert(e.getMessage());
}
g.drawImage(img, 0, 0, 0) は NullPointerException をスローします。つまり、img は null ( http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/Graphics.html ) です。ImageItem とその NOT null で img を使用できます。問題は何ですか?