Note that there are some explanatory texts on larger screens.

plurals
  1. POGet ISBN from Google Books API
    text
    copied!<p>I have been trying all evening to get ISBN number from google Books API from book title. So far after trying several solution from SO and Google, I have come upto below code where I am getting error in the line "BufferedReader responseReader = new BufferedReader........"</p> <p>My head is now totally blocked, so any help will be very very much appreciated ...</p> <p>(I have API Key, which I am not using here during testing)</p> <p><strong>CODE:</strong></p> <pre><code>public void getGoogle(View v) { String result = ""; String link = "https://www.googleapis.com/books/v1/volumes?q=intitle:'farmer+boy'+inauthor:'laura+ingalls+wilder'&amp;projection=full&amp;langRestrict=en&amp;maxResults=1"; HttpURLConnection connection = null; try { URL url = new URL(link); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); } catch (Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } try { StringBuilder builder = new StringBuilder(); BufferedReader responseReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "iso-8859-1"),8); String line = responseReader.readLine(); while (line != null){ builder.append(line + "\n"); line = responseReader.readLine(); } connection.disconnect(); result = builder.toString(); } catch (Exception e) { Log.e("log_tag", "Error converting result: " + e.toString()); } // parse json data try { JSONArray jArray = new JSONArray(result); String isbn; JSONObject json = jArray.getJSONObject(0); isbn = json.getString("kind"); EditText isbnfld = (EditText) findViewById(R.id.isbn); isbnfld.setText(isbn); } catch (JSONException e) { Toast.makeText(getApplicationContext(), "Error parsing data.", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "Problem importing data.", Toast.LENGTH_LONG).show(); } } </code></pre> <p><strong>LOGCAT:</strong></p> <pre><code>12-04 11:32:06.025: E/log_tag(1761): Error converting result: android.os.NetworkOnMainThreadException </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload