I am new to the development on android, please do not judge strictly.

I make a GET request to the server, which returns us an array of objects. I save the data I saw in the List. But because of the lines newsList = api.getNews(jwtToken); The application crashes, although I seem to have written everything correctly.

I would like to know why the application crashes and how to fix it. Code below

 public class News extends ActionBarActivity { RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(Api.URL) .build(); Api api = restAdapter.create(Api.class); TextView newsText; SharedPreferences sPref; String jwtToken; List<news> newsList = new ArrayList<>(); public class news { String id, title, text, user, group, tags, comments, documents; public news(String id, String title, String user, String group, String tags, String comments, String documents){ this.id=id; this.title=title; this.user=user; this.group=group; this.tags=tags; this.comments=comments; this.documents=documents; } public news (){} public String getId(){return id;} public String getTitle(){return title;} public String getText() { return text; } public String getComments() { return comments; } } public interface Api{ public static final String URL ="http://178.62.42.66/api/v1"; public final String NEWS="/news/"; @GET(NEWS) List<news> getNews(@Header("Authorization") String jwtToken); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.news); newsText = (TextView)findViewById(R.id.TextNew); sPref = getSharedPreferences("MyPref",MODE_PRIVATE); String savedText = sPref.getString("token",""); jwtToken = "JWT "+savedText; String url = "http://178.62.42.66/api/v1/news/"; Runnable runnable = new Runnable() { public void run() { newsList = api.getNews(jwtToken); String text = newsList.get(1).getTitle(); } }; Thread thread = new Thread(runnable); thread.start(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } 

}

  • Attach Exception Text - hardsky
  • @hardsky I don’t know how to do it - Aleksandr Gnatyuk
  • If you run in AndroidStudio, then the crash should be displayed in one of the auxiliary windows of the studio. - hardsky
  • @hardsky is that what you need? pastebin.com/0zvcmg41 - Aleksandr Gnatyuk
  • Yes, check out the news class, which is converted to json "retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but it was BEGIN_ARRAY at line 1 column 151 path $ [0] .documents", you in the class some kind of string field, which actually should be a collection (or an array). - hardsky

0