I have a class HandleJson
that have a method QuestionDone
like below:
public class HandleJSON {
public AtomicBoolean QuestionDone(final String params) {
final AtomicBoolean b = new AtomicBoolean(false);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
String urlParameters = params;
URL url = new URL("http://192.168.x.xx:xxxx/question_done");
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
conn.setReadTimeout(30000 /* milliseconds */);
conn.setConnectTimeout(50000 /* milliseconds */);
conn.setRequestMethod("GET");
// conn.setRequestProperty("User-Agent",
// "GYUserAgentAndroid");
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoInput(true);
// conn.setUseCaches (false);
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn
.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
// Starts the query
conn.connect();
System.out.println("Before url.openStream()");
InputStream stream = conn.getInputStream();// .openStream();
System.out.println("After url.openStream()");
String data = convertStreamToString(stream);
data = data.replace("\"", "").trim();
String temp = "";
temp = data.substring(0, data.indexOf(" "));
if (temp.equals("Thanks"))
b.set(true);
else
b.set(false);
readAndParseJSON(data);
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
b.get();
return b;
}
}
And I am calling this method from my activity through a button like below:
public class QuestionActivity extends ActionBarActivity implements
GetQuestionAndAnswerList {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_question);
btn_parentDone = (Button) findViewById(R.id.btn_parentDone);
btn_parentDone.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AtomicBoolean res;
concat_str = "abc";
res = obj.QuestionDone(concat_str);
}
});
}
}
But I am getting below error or exception
at this line res = obj.QuestionDone(concat_str);
:
12-15 09:49:25.486: D/dalvikvm(628): GC_FOR_ALLOC freed 516K, 9% free 9855K/10759K, paused 47ms, total 50ms
Kindly suggest me, how can I resolve this issue.
waiting for reply.
Thanks