收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 天气预报,java.lang.NullPointerException

szp895 2009-09-04 11:04:41
有个在天气预报的问题,老是出错,要求只要在模拟器里面显示网上时时更新的预报图片即可。

import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Weather extends MIDlet implements CommandListener, Runnable {

private Display mDisplay;
private Command mExitCommand;
private Command mForecastCommand;
private Command mWeatherCommand;
private Image mImage1;
private Image mImage2;
private String mUrl1;
private String mUrl2;
mUrl1 = "http://www.weatherzone.com.au/wzservlet/wzwoys/button?postcode=2615&locality=FLOREY&type=0"; //weather image
mUrl2 = "http://www.weatherzone.com.au/wzservlet/wzwoys/button?postcode=2615&locality=FLOREY&type=1"; //forecast image

private Form mForm;

public Weather() {
mForm = new Form("Weather");
mImage1 = loadImage(mUrl1);
mImage2 = loadImage(mUrl2);

mExitCommand = new Command("Exit", Command.EXIT, 0);
mWeatherCommand = new Command("Weather", Command.SCREEN, 0);
mForecastCommand = new Command("Forecast", Command.SCREEN, 0);
mForm.addCommand(mExitCommand);
mFrom.addCommand(mWeatherCommand);
mForm.addCommand(mForecastCommand);

mForm.setCommandListener(this);
}

public void startApp() {
mDisplay = Display.getDisplay(this);
mForm.append(mImage1);
mForm.append(mImage2);
mDisplay.setCurrent(mForm);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void commandAction(Command c, Displayable s) {
if (c == mExitCommand) {
destroyApp(false);
notifyDestroyed();
}

if (c == mWeatherCommand)
{
Alert mAlert = new Alert("Alert", "Weather clicked", mImage1, AlertType.INFO);
mAlert.setTimeout(2000);
mAlert.setImage(mImage1);
mDisplay.setCurrent(mAlert, mForm);
}

if (c == mForecastCommand) {
Alert mAlert = new Alert("Alert", "Forecast clicked", mImage2, AlertType.INFO);
mAlert.setTimeout(2000);
mAlert.setImage(mImage2);
mDisplay.setCurrent(mAlert, mForm);
}
}

public void run() {}

private Image loadImage(URL url) {
Image image = null;
try {
image = Image.createImage(url);
}
catch (IOException ioe) {
System.out.println(ioe);
}
return image;
}
}



这是错误提示。。请问该怎么改?
java.io.IOException
java.io.IOException
startApp threw an Exception
java.lang.NullPointerException
java.lang.NullPointerException
at javax.microedition.lcdui.Form.append(+11)
at Weather.startApp(+19)
at javax.microedition.midlet.MIDletProxy.startApp(+7)
at com.sun.midp.midlet.Scheduler.schedule(+270)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+116)
...全文
62 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gesanri 2009-09-04
  • 打赏
  • 举报
回复
Image.createImage(url);API有这个方法吗?直接把网址传进去就可以?是不是应该先用HttpConnection打开链接再处理
szp895 2009-09-04
  • 打赏
  • 举报
回复
刚刚发错地方了,特转移过来。

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧