nokia 6600 用http下载图片并在手机上面显示的问题,解决再给500分

thunderxs 2004-08-30 05:12:24
这个类在nokia3650上面用没问题,但是在6600上就出错,http去打开的流,说可获得的字节是0
捕获的异常是symbian os err 晕了。那位大哥做过6600的网络下载来交流一下
下面是Canvas的类,url我没写出来,这是没错
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import com.nokia.mid.ui.*;
public class MainCanvas extends FullCanvas implements Runnable{
boolean gameState;
Thread gameThread;
Image fire;
int totalDataLength;
int getLength;
public MainCanvas(){
gameState=true;
fire=getPic();
gameThread=new Thread(this);
gameThread.start();
}

public void clear(Graphics g){
g.setColor(0,0,0);
g.fillRect(0,0,w,h);
}


public void paint(Graphics g){
clear(g);
g.drawImage(fire,0,0,0);

}

Image getPic() {
Image image=null;
HttpConnection con=null;
InputStream ins=null;
try{
con=(HttpConnection) Connector.open("url", Connector.READ,true);
con.setRequestMethod(HttpConnection.GET);
ins=con.openInputStream();
totalDataLength=(int)(con.getLength());
int data=0;
byte[] imageData=new byte[totalDataLength];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while (((data = ins.read()) != -1) ){
baos.write(data);
}
imageData=baos.toByteArray();
getLength=imageData.length;
baos.close();
image=Image.createImage(imageData,0,imageData.length);
if(ins!=null){
ins.close();
}
if (con!=null){
con.close();
}
}catch(IOException e){
System.out.println(e.getMessage());
}
finally{
try{
if(ins!=null){
ins.close();
}
if (con!=null){
con.close();
}
}catch(Exception ex){
}
}
return image;
}

public void run(){
while(gameState){
try{
Thread.sleep(10);
}catch(Exception e){
System.out.println(""+e);
}
repaint();
System.gc();
}
}

public void showNotify(){
gameState=true;
}

public void hideNotify(){
gameState=false;
}
}
...全文
167 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
nik_Amis 2004-09-01
  • 打赏
  • 举报
回复
up
mousefog 2004-09-01
  • 打赏
  • 举报
回复
up!楼主能告诉我门是怎么解决的?大家学习一下
thunderxs 2004-09-01
  • 打赏
  • 举报
回复
6600在上网的时候需要选择通过gprs接入互联网,这样才可以通过http去下载文件
zhang21cnboy 2004-08-31
  • 打赏
  • 举报
回复
我在MOTO的手机上,碰到这个问题...输入流没有读完,它就异常了.哎.
zhang21cnboy 2004-08-31
  • 打赏
  • 举报
回复
怎么解决的?
跟MIDP的版本是否有关系啊?
thunderxs 2004-08-31
  • 打赏
  • 举报
回复
自己解决了,谁来顶一下,就给分
prok 2004-08-30
  • 打赏
  • 举报
回复
有可能是os的版本不兼容。

13,097

社区成员

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

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