关于S40从网络下载文件的问题

来源:互联网 发布:防止数据倾斜 编辑:程序博客网 时间:2024/04/28 14:23

代码在S60和模拟器上运行都正常,但放在S40时,就老是系统崩溃退出了(Null Pointer java/lang/NullPointerException)

Java code
//判断联网方式,为真时使用CMWAP代理方式if (Tool.isWap) { int findIndex = url.indexOf("/", 7); String serverName = url.substring(7, findIndex); String serverPath = url.substring((findIndex + 1), url.length()); conn = (HttpConnection) Connector.open( "http://10.0.0.172:80/" + serverPath, Connector.READ_WRITE, true); conn.setRequestMethod(HttpConnection.GET); conn.setRequestProperty("X-Online-Host", serverName); conn.setRequestProperty("Accept", "*/*");}//使用CMNET方式联网else { conn = (HttpConnection) Connector.open(url,Connector.READ_WRITE, true); conn.setRequestMethod(HttpConnection.GET);}//使用字节流下载conn.setRequestProperty("Content-Type", "application/octet-stream");//分段下载文件conn.setRequestProperty("RANGE", "bytes=" + localTempFileSize + "-" + (localTempFileSize+50000));//添加Debug信息(可通过点击手机指定组合的按键,在手机屏幕上显示Debug信息内容)MainMidlet.debug.AddMsg("get response");//获取状态码int httpState = conn.getResponseCode();




//获取状态码——这一段老是运行不下去,每次运行到这里,软件就直接崩溃退出了(抛出的异常是:Null Pointer java/lang/NullPointerException)

int httpState = conn.getResponseCode();


各位老大帮忙看看是怎么回事,这个问题已经困挠我一周多了,用过其他方式来代替也是出错(用POST方式就比较正常,但是用服务器端写出字节流,客户端在接收时,在读取最后一段字节时也同样崩溃退出了,异常同上面的一样)

//获取状态码
int httpState = conn.getResponseCode();

你看下是不是conn为空撒

getResponseCode这个函数貌似不会抛出空指针异常的。
是不是再调试下看看,做个异常捕获

获取状态码
int httpState = conn.getResponseCode();

这个抛得是IO异常才对。。没做过分段下载。。

来源:足球直播

 

原创粉丝点击