在诺基亚 s40 Asha 305 设备中加载不同 URL 时出现内存不足错误,但我的相同代码在 Asha501 中运行良好。
我该怎么办??任何人都可以帮助我。我已经为网络响应添加了我的数据检索代码
public static String getDataFromServer(String serverUrl) {
HttpsConnection httpConn = null;
InputStream is = null;
String dataRead = "";
try {
httpConn = (HttpsConnection) Connector.open(serverUrl);
if ((httpConn.getResponseCode() == HttpsConnection.HTTP_OK)) {
int length = (int) httpConn.getLength();
is = httpConn.openInputStream();
if (length == -1) {
int chunkSize = 1023;
byte[] data = new byte[chunkSize];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int dataSizeRead;
while ((dataSizeRead = is.read(data)) != -1) {
baos.write(data, 0, dataSizeRead);
}
dataRead = new String(baos.toByteArray());
baos.close();
} else {
DataInputStream dis = new DataInputStream(is);
byte[] data = new byte[length];
dis.readFully(data);
dataRead = new String(data);
}
} else {
dataRead = SERVER_ERROR;
}
} catch (Throwable t) {
dataRead = NO_CONNECTION;
} finally {
try {
if (is != null) {
is.close();
}
} catch (Throwable t) {
}
try {
if (httpConn != null) {
httpConn.close();
}
} catch (Throwable t) {
}
}
return dataRead;
}