public void run() {
try {
sendMessage("Query,map,$,start,211,Arsenal,!");
String unformattedurl = receiveMessage();
String url = getURL(unformattedurl);
// url = "http://maps.google.com/maps/api/staticmap?center=100,20&zoom=14&size=500x400&format=JPEG&maptype=roadmap&sensor=false";
URL = getURL1(unformattedurl);
try {
System.out.println("Thread1...");
image .setImage( loadImage(URL) );
} catch (Exception ex) {
stringItem.setText(stringItem.getText() + "Err1"+ex.getMessage());
}
} catch (Exception ex) {
stringItem.setText(stringItem.getText()+"Error2 " + ex.getMessage());
}
}
public Image loadImage(String url) throws IOException {
stringItem.setText(stringItem.getText() + url);
HttpConnection hpc = null;
DataInputStream dis = null;
try {
hpc = (HttpConnection) Connector.open(URL);
int length = (int) hpc.getLength();
System.out.println("Length is "+length);
stringItem.setText(stringItem.getText() + "len" +length);
byte[] data = new byte[length];
dis = new DataInputStream(hpc.openInputStream());
dis.readFully(data);
return Image.createImage(data, 0, data.length);
} finally {
if (hpc != null)
hpc.close();
if (dis != null)
dis.close();
}
}
private String getURL1(String message) {
return "http://maps.google.com/maps/api/staticmap?center=Mauritius&zoom=10&size=200x200&maptype=roadmap&markers=color:Blue|label:U|22.0,22.0&markers=color:Green|label:B|21.0,21.0&sensor=false";
}
Когда я запускаю приведенный выше код со статическим URL-адресом, то есть URL-адрес, сохраненный в строке, работает нормально, но когда я беру тот же URL-адрес и возвращаю его из функции, я получаю нулевое исключение и размер изображения-1 ..