Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Logcat says:
W/System.err: org.json.JSONException

Can someone please help me sort this out by going through the code.

Here is the code:

 public class MainActivity extends AppCompatActivity {
 Button click;
 public static  TextView tv_data;

protected void onCreate(Bundle savedInstanceState) {

    click = (Button)findViewById(;
    tv_data = (TextView)findViewById(;

    click.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            fetchData process   = new fetchData();


public class fetchData extends AsyncTask<Void,Void,Void> {

String products="";
String dataParsed = "";
String singleParsed = "";
protected Void doInBackground(Void... voids) {
    try {
        URL url = new URL("");
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        InputStream inputStream = httpURLConnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

        String line="";
        while (line!=null){
            line= bufferedReader.readLine();
            products= products+line;

        JSONArray JA = new JSONArray(products);
        for(int i=0;i<JA.length();i++){
            JSONObject JO = (JSONObject) JA.get(i);
            singleParsed = "Name:" + JO.get("name") + "\n" +
                           "Description:" + JO.get("description") + "\n" +
                           "Price:" + JO.get("price") + "\n" +
                           "Currency:" + JO.get("cost_currency") + "\n" ;

            dataParsed  = dataParsed+singleParsed + "\n";


    } catch (MalformedURLException e) {
    } catch (IOException e) {
    } catch (JSONException e) {
    return null;

protected void onPostExecute(Void aVoid) {

What I have tried:

I'am trying to fetch details of products from a URL . However, there is a json exception when trying to parse the JSON objects.
Updated 13-Apr-18 20:19pm
Richard MacCutchan 14-Apr-18 3:58am    
You need to capture the text that causes the exception.
Sukhi_15 16-Apr-18 1:57am    
yup.. thanks.. i got it solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900