0
私はj2meプロジェクトで、通常の作業の2日後に崩壊するメソッドを持っています。提示されるエラーは以下の通りである。J2me - OutofMemory in HTTPリクエスト
Contacting website...
java.lang.OutOfMemoryError
(stack trace incomplete)
前記の方法は、ウェブサイトとの通信に使用される方法である。それは文字列とモードセレクタ(i = 1またはsmth else)を受け取り、リクエストを処理します。コードは次のとおりです。
void enviarPost(int i, String comando)throws IOException, IllegalStateException, IllegalArgumentException, ATCommandFailedException{
System.out.println("Contacting website...");
if(i == 1)
{
url = "http://websitedummy.com.pl/index.php?IMEI=" + imeiX + "&IP=" + ipX;
}
//53543D303B44723D4E616F
else
{
url2 = comando;
url = "http://websitedummy.com.pl/index.php?data={\"IMEI\":\""+imeiX+"\",\"TS\":\"20/04/13-08:31:44\",\"SER\":\""+url2+"\"}";
}
try {
Thread.sleep(1000);
connection = (HttpConnection) Connector.open(url);
Thread.sleep(500);
connection.setRequestMethod(HttpConnection.GET);
Thread.sleep(500);
connection.setRequestProperty("Content-Type", "text/plain");
Thread.sleep(500);
int con = 0;
try{
con = connection.getResponseCode();
} catch (Exception e4)
{
System.out.println(e4);
}
if (con == HttpConnection.HTTP_OK) {
System.out.println("Vamos");
inputstream_ = connection.openInputStream();
int ch;
while ((ch = inputstream_.read()) != -1) {
dataReceived.append((char) ch);
}
System.out.println("Atualizado.");
acabouatualizar=1;
inputstream_.close();
connection.close();
} else {
System.out.println("Error");
// Connection not ok
}
} catch (Exception e) {
System.out.println("EXCEÇÂO 1 - " + e);
} finally {
if (inputstream_ != null) {
try {
inputstream_.close();
} catch (Exception e1) {
System.out.println("EXCEÇÂO 2- " + e1);
}
}
if (connection == null) {
try {
System.out.println("Fechou conexao.");
connection.close();
} catch (Exception e2) {
System.out.println("EXCEÇÂO 3- " + e2);
}
}
}
}
問題を解決するために、私は接続で使用されるすべての変数をクリアすることを考えました。問題は、エラーが発生するのに2日かかり、これが私に多大な時間を要してしまうため、問題の原因がほとんどわかっていることです。
提案がありますか? ありがとうございます。
さらにスタックトレースを提供できますか? –
悲しいことに、これは当時の私が得ている唯一の出力です。 – kohhworlwide
あなたのコードにはいくつかの誤りがあります。 finallyブロックで入力ストリームと接続を閉じたので、ifブランチでそれらを閉じる必要はありません。 if(connection == null)をif(connection!= null)に変更します。 –