Z poprzednimi problemami się uporałem.
Na tą chwilę działa wyświetlanie listy zgłoszeń. Natomiast problem leży w wyświetleniu detali pojedynczego zgłoszenia.
protected String doInBackground(String... args) {
runOnUiThread(new Runnable() {
public void run() {
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pid", pid));
[b]Log.d("pid", pid.toString());[/b]
JSONObject json2 = jsonParser.makeHttpRequest(url_issues_detials, "GET", params);
[b]Log.d("Issue Details", json2.toString());[/b]
success = json2.getInt(TAG_SUCCESS);
if (success == 1) {
JSONArray issueObj = json2.getJSONArray(TAG_PID); // JSON Array
JSONObject issue = issueObj.getJSONObject(0);
.................................
Program dochodzi do momentu, w którym wykonywana jest funkcja makeHttpRequest,
jednak nie dochodzi do jej wykonania w pełni.
W logu pid wartość pid jest prawidłowa, natomiast log Issue Details w ogóle nie powstaje.
Tu log
001-19 17:46:26.970 19657-19657/com.pjotrek.mantisreader D/pid﹕ 1
01-19 17:46:26.972 19657-19657/com.pjotrek.mantisreader D/http﹕ http://192.168.0.15/android_connect/issue_details.php?pid=1
01-19 17:46:26.988 19657-19657/com.pjotrek.mantisreader D/AndroidRuntime﹕ Shutting down VM
01-19 17:46:26.988 19657-19657/com.pjotrek.mantisreader W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41701d40)
01-19 17:46:27.007 19657-19657/com.pjotrek.mantisreader E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.pjotrek.mantisreader, PID: 19657
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
at libcore.io.IoBridge.connect(IoBridge.java:112)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:460)
at java.net.Socket.connect(Socket.java:833)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:374)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:575)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:498)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:476)
at com.pjotrek.mantisreader.JSONParser.makeHttpRequest(JSONParser.java:63)
at com.pjotrek.mantisreader.ViewIssueDetailsActivity$GetIssueDetails$1.run(ViewIssueDetailsActivity.java:128)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
gdzie ViewIssueDetailsActivity.java:128 to jest ta linia
JSONObject json2 = jsonParser.makeHttpRequest(url_issues_detials, "GET", params);
a JSONParser.java wywala się na tej metodzie
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if(method == "POST"){
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}else if(method == "GET"){
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
Log.d("JSON", json);
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
Adres url do zapytania tworzony jest prawidłowo, po wklejeniu do przeglądarki daje prawidłowy wynik - wyświetla porządane dane. Jednak do JSON-a te dane już nie docierają i wywala aplikację.
Pomoże ktoś rozwiązać ten problem? Siedzę już parę ładnych godzin nad tym i nie wiem, co jeszcze mogę zrobić, aby to zadziałało.