Здравствуйте. Не знаю, были ли подобные вопросы, т.к. не могу увидеть даже ошибку в logcat. Есть некий API куда посылается get запрос. В ответ приходит string данные(json файл в формате String). До тех пор, пока данных было немного 10-15(данные о предприятиях) всё отображалось хорошо. После того как на сервер в бд залили около 8k предприятий получаю такое:
08-14 19:06:09.342 31035-31035/fess.com.city_online D/responseAPI: responseCode 200
08-14 19:06:09.491 31035-31035/fess.com.city_online W/System.err: org.json.JSONException: Value {"count":8058,"next":"http:\/\/айпиадресс\/places\/update_cache\/?last_update=2017-1-1+0%3A0%3A0&limit=500&offset=500","previous":null,"results":[{"id":11,"category_name":"Авто","subcategory_name":"Автоаксессуары","schedules":[{"id":7,"day_start":5,"day_end":5,"time_start":"09:00:00","time_end":"15:00:00","place":11},{"id":6,"day_start":0,"day_end":4,"time_start":"09:00:00","time_end":"18:00:00","place":11}],"photos":[],"rating":null,"name":"Exist.ua","about":"","coordinates":"48.6109198;22.3003149","address":"Украина, Закарпатская область, Ужгород, Станционная улица, 16\/1\n","phones":["380503000488","380673148435"],"site":"http:\/\/www.exist.ua","budget":false,"premium":false,"day_start":null,"last_update":"2017-08-11 21:30:14","category":1,"subcategory":1},{"id":12,"category_name":"Авто","subcategory_name":"Автоаксессуары","schedules":[{"id":9,"day_start":5,"day_end":5,"time_start":"09:00:00","time_end":"15:00:00","place":12},{"id":8,"day_start":0,"day_end":4,"time_start":"09:00:00","time_end":"18:00:00","place":12}],"photos":[],"rating":null,"name":"Exist.ua","about":"","coordinates":"48.6110759;22.3004925","address":"Закарпатская область, Ужгород, Станционная улица, 10\n","phones":["380312614349","380503000488","380673148435"],"site":"http:\/\/www.exist.ua","budget":false,"premium":false,"day_start":null,"last_update":"2017-08-11 21:30:14","category":1,"subcategory":1},{"id":13,"category_name":"Авто","subcategory_name":"Автоаксессуары","schedules":[{"id":11,"day_start":5,"day_end":5,"time_start":"09:00:00","time_end":"16:00:00","place":13},{"id":10,"day_start":0,"day_end":4,"time_start":"09:00:00","time_end":"19:00:00","place":13}],"photos":[],"rating":null,"name":"Exist.ua","about":"","coordinates":"48.6206823;22.2911579","address":"Ужгород, ул. Льва Толстого, 31\n","phones":["380312614349"],"site":"http:\/\/www.exist.ua","budget":false,"premium":false,"day_start":null,"last_update":"2017-08-11 21:30:15","category":1,"subcategory":1},{"id":14,"category_name":"Авто","subcategory_name":"Автоаксессуары","schedules":[{"id":13,"day_start":5,"day_end":5,"time_start":"10:00:00","time_end":"15:00:00","place":14},{"id":12,"day_start":0,"day_end":4,"time_start":"09:00:00","time_end":"18:00:00","place":14}],"photos":[],"rating":null,"name":"Автомагазин Гран","about":"","coordinates":"48.61840249999999;22.2980561","address":"Закарпатская область, город Ужгород, улица Мукачевская, 2\n","phones":["380312614695"],"site":null,"budget":false,"premium":false,"day_start":null,"last_update":"2017-08-11 21:30:16","category":1,"subcategory":1},{"id":15,"category_name":"Авто","subcategory_name":"Автоаксессуары","schedules":[{"id":16,"day_start":6,"day_end":6,"time_start":"11:00:00","time_end":"17:00:00","place":15},{"id":15,"day_start":5,"day_end":5,"time_start":"10:00:00","time_end":"17:00:00","place":15},{"id":14,"day_start":0,"day_end":4,"time_start":"09:00:00","time_end":"19:00:00","place":15}],"photos":[],"rating":null,"name":"Идеал М","about":"","coordinates":"","address":"Закарпатская область, Ужгородский район, село Баранинцы, Европейская улица, 1\n","phones":["380503005595"],"site":"https:\/\/bmwidealm.com","budget":false,"premium":false,"day_start":null,"last_update":"2017-08-11 21:30:16","category":1,"subcategory":1},{"id":16,"category_name":"Авто","subcategory_name":"Автоаксессуары","schedules":[{"id":18,"day_start":5,"day_end":5,"time_start":"09:00:00","time_end":"15:00:00","place":16},{"id":17,"day_start":0,"day_end":4,"time_start":"09:00:00","time_end":"18:00:00","place":16}],"photos":[],"rating":null,"name":"Интернет-магазин Strans-shop","about":"","coordinates":"48.6151318;22.2899488","add
08-14 19:06:09.491 31035-31035/fess.com.city_online W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
08-14 19:06:09.491 31035-31035/fess.com.city_online W/System.err: at org.json.JSONArray.<init>(JSONArray.java:96)
08-14 19:06:09.491 31035-31035/fess.com.city_online W/System.err: at org.json.JSONArray.<init>(JSONArray.java:108)
08-14 19:06:09.491 31035-31035/fess.com.city_online W/System.err: at fess.com.city_online.fragments.FragmentCityOnline$2.onResponse(FragmentCityOnline.java:103)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at fess.com.city_online.api.ApiDataGet.onPostExecute(ApiDataGet.java:79)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at fess.com.city_online.api.ApiDataGet.onPostExecute(ApiDataGet.java:17)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at android.os.AsyncTask.finish(AsyncTask.java:660)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at android.os.AsyncTask.-wrap1(AsyncTask.java)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at android.os.Looper.loop(Looper.java:154)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6776)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at java.lang.reflect.Method.invoke(Native Method)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
08-14 19:06:09.492 31035-31035/fess.com.city_online W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Как видите текст ошибки не полный... "Value ...Json object... и всё...
Класс Get запроса:
import android.os.AsyncTask;
import android.util.Log;
import org.json.JSONException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import fess.com.city_online.util.Cons;
public class ApiDataGet extends AsyncTask<String , Void ,String> {
private String token;
private static OnResponseListener mResponseListener;
public interface OnResponseListener {
void onResponse(String response, int responseCode) throws JSONException;
}
public void setOnResponseListener(OnResponseListener listener) {
mResponseListener = listener;
}
public ApiDataGet(String token){
this.token = token;
}
private String server_response;
private int responseCode;
@Override
protected String doInBackground(String... strings) {
Log.d("responseAPI", "doInBackground()");
URL url;
HttpURLConnection conn = null;
try {
url = new URL(strings[0]);
Log.d("responseAPI", "ApiDataGet url: " + strings[0]);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty(Cons.http.HEAD_CONTENT, Cons.http.TYPE_APPLICATION);
conn.setRequestProperty("Authorization", "Token " + token);
responseCode = conn.getResponseCode();
Log.d("responseAPI", "responseCode = " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
server_response = readStream(conn.getInputStream());
Log.d("responseAPI", "Response = " + server_response);
}else{
server_response = readStream(conn.getErrorStream());
Log.d("responseAPI", "Response = " + server_response);
}
} catch (IOException e) {
e.printStackTrace();
Log.d("responseAPI", "error: " + e.toString());
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Log.e("Response", "" + server_response);
if(mResponseListener != null){
try {
mResponseListener.onResponse(server_response, responseCode);
} catch (JSONException e) {
e.printStackTrace();
}
mResponseListener = null;
}
}
// Converting InputStream to String
private String readStream(InputStream in) {
BufferedReader reader = null;
StringBuffer response = new StringBuffer();
try {
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null) {
response.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return response.toString();
}
}
И обработка полученных данных:
private JSONArray eventsData;
ApiDataGet dataGet = new ApiDataGet(sp.getString(Cons.sp.TOKEN, ""));
dataGet.setOnResponseListener(new ApiDataGet.OnResponseListener() {
@Override
public void onResponse(String response, int responseCode) throws JSONException {
Log.d("responseAPI", "response " + response);
Log.d("responseAPI", "responseCode " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
**eventsData = new JSONArray(response)**;
............................... ругается на строчку выше
} else {
Log.d("responseAPI", "eventsData == null");
//показать табличку ошибка сервера
}
}
});
dataGet.execute(Cons.http.API_EVENTS_ALL);
Ругается на строку:
eventsData = new JSONArray(response);
Но приложение не вылетает.
Заранее спасибо!
Есть данные Name, NewtworkStatusих несколько десятков от 50+ Я пытаюсь отобразить список через ListView и SimpleAdapter
Есть поле для вводе текста, допустим ищем пользователей по имени в БДЕсть метод (упрощенный), который выполняется при каждом наборе символа
Есть страница авторизации которую Spring Security должен отдать но что-то идет не так и я получаю 404Помогите пожалуйста разобраться в чем моя ошибка