I'm running my API REST application from my mobile device and, apparently, it doesn't have any error because it doesn't close or kill the process automaticaly. It just run but without retrieving to me any information and it shows to me two erros in the log console.
Here is one of the problems that I saw in my log console: acAppName=/system/bin/surfaceflinger
.
06-04 16:49:21.527 17600-17600/com.example.user.project V/PhoneWindow﹕ DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{420a1478 com.example.user.project/com.example.user.project.MainActivity,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{4205a608 V.E..... R.....ID 0,0-0,0}
06-04 16:49:21.527 17600-17600/com.example.user.project D/ActivityThread﹕ ACT-LAUNCH_ACTIVITY handled : 0 / ActivityRecord{4204b3c0 token=android.os.BinderProxy@4204aa68 {com.example.user.project/com.example.user.project.MainActivity}}
06-04 16:49:21.590 17600-17600/com.example.user.project E/﹕ appName=com.example.user.project, acAppName=/system/bin/surfaceflinger
06-04 16:49:21.590 17600-17600/com.example.user.project E/﹕ 0
06-04 16:49:21.590 17600-17600/com.example.user.project E/﹕ appName=com.example.user.project, acAppName=/system/bin/surfaceflinger
06-04 16:49:21.590 17600-17600/com.example.user.project E/﹕ 0
06-04 16:49:21.592 17600-17600/com.example.user.project D/GraphicBuffer﹕ create handle(0x614af178) (w:480, h:800, f:1)
06-04 16:49:21.593 17600-17600/com.example.user.project I/MaliEGL﹕ [Mali]window_type=1, is_framebuffer=0, errnum = 0
And some lines below I get this another problem:
06-04 17:32:24.340 23481-23503/com.example.user.project I/System.out﹕ >doSendRequest
06-04 17:32:24.341 23481-23503/com.example.user.project I/System.out﹕ <doSendRequest
06-04 17:32:24.382 23481-23503/com.example.user.project E/ServicioRest﹕ org.json.JSONException: Value {//Here the information retrieved of my JSON} of type org.json.JSONObject cannot be converted to JSONArray
06-04 17:32:24.399 23481-23481/com.example.user.project D/ListView﹕ measureHeightOfChildren adapter=com.com.example.user.project
I searched about both errors but for the first one I couldn't find anything that helped me but for the second one I found this: org.json.JSONObject cannot be converted to JSONArray in android
And I wanted to apply what RajaReddy PolamReddy
said:
JSONObject object = new JSONObject(result); JSONArray Jarray = object.getJSONArray("contacts"); for (int i = 0; i < Jarray.length(); i++) { JSONObject Jasonobject = Jarray.getJSONObject(i);
but I don't know how to apply it to my code:
HttpClient httpClient = new DefaultHttpClient();
HttpGet method = new HttpGet(url);
method.setHeader("content-type", "application/json");
try{
HttpResponse response = httpClient.execute(method);
String responseString = EntityUtils.toString(response.getEntity());
JSONArray responseJSON = new JSONArray(responseString);
for(int i=0; i<responseJSON.length(); i++){
JSONObject object = responseJSON.getJSONObject(i);
}
}catch{
Log.e("ServiceRest", ex.toString());
}
where url
is the uri which access to my GET
method of my API REST.
Note: I'm using my mobile device to access to the uri
. Instead of localhost
, because I'm in an external device, I'm using the IP network of my computer. I also tried with 10.0.2.2
and it doesn't work so please avoid answers that recommend me to use 10.0.2.2
as IP.
Note2: I have these permissions on my Manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
Are both erros related? How can I solve them? Do you know why the first one appears?
Thanks in advance!
EDIT
What I retrieve of my JSON is (I simplified it, I put here the different types of data that it is retrieving):
int idMain = object.getInt("idMain");
String date = object.getString("date");
String name = object.getString("name");
double value = object.getDouble("value");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date datePar = sdf.parse(date);