Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:53:15+00:00 2026-06-15T08:53:15+00:00

I`m consuming asp.net web api in my android app. But it gives me an

  • 0

I`m consuming asp.net web api in my android app. But it gives me an error. my returning string is in JSON format.
below is my log cat

11-30 12:44:02.760: W/ActivityThread(821): Application com.example.test is waiting for the debugger on port 8100...
11-30 12:44:02.811: I/System.out(821): Sending WAIT chunk
11-30 12:44:02.820: I/dalvikvm(821): Debugger is active
11-30 12:44:02.900: I/System.out(821): Debugger has connected
11-30 12:44:02.900: I/System.out(821): waiting for debugger to settle...
11-30 12:44:03.099: I/System.out(821): waiting for debugger to settle...
11-30 12:44:03.299: I/System.out(821): waiting for debugger to settle...
11-30 12:44:03.509: I/System.out(821): waiting for debugger to settle...
11-30 12:44:03.709: I/System.out(821): waiting for debugger to settle...
11-30 12:44:03.910: I/System.out(821): waiting for debugger to settle...
11-30 12:44:04.113: I/System.out(821): waiting for debugger to settle...
11-30 12:44:04.319: I/System.out(821): waiting for debugger to settle...
11-30 12:44:04.519: I/System.out(821): waiting for debugger to settle...
11-30 12:44:04.721: I/System.out(821): waiting for debugger to settle...
11-30 12:44:04.930: I/System.out(821): debugger has settled (1324)
11-30 12:46:27.210: E/log_tag(821): Error converting result org.json.JSONException: Value [{"Name":"Panadol","Batch":"B030","Id":1,"Expiry":"12\/11\/2013","Type":"Tablet","Price":"12"},{"Name":"Velosef 500mg","Batch":"B069","Id":2,"Expiry":"06\/12\/2014","Type":"Capsule","Price":"100"},{"Name":"Tandegyl 120ml","Batch":"B097","Id":3,"Expiry":"09\/08\/2015","Type":"Syrup","Price":"120"},{"Name":"Acefyl","Batch":"B78","Id":4,"Expiry":"03\/12\/2014","Type":"Syrup","Price":"50"},{"Name":"Tyno","Batch":"B79","Id":5,"Expiry":"03\/06\/2015","Type":"Syrup","Price":"48"},{"Name":"Nocid 40mg","Batch":"BN09","Id":6,"Expiry":"11\/09\/2013","Type":"Tablet","Price":"60"},{"Name":"Lipiget 100mg","Batch":"B090","Id":7,"Expiry":"09\/09\/2015","Type":"Tablet","Price":"250"}] of type org.json.JSONArray cannot be converted to JSONObject
11-30 12:46:42.319: D/dalvikvm(821): Debugger has detached; object registry had 498 entries
11-30 12:46:42.333: I/dalvikvm(821): ignoring registerObject request in thread=1
11-30 12:46:42.333: I/dalvikvm(821): ignoring registerObject request in thread=1
11-30 12:46:42.333: D/AndroidRuntime(821): Shutting down VM
11-30 12:46:42.333: W/dalvikvm(821): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-30 12:46:42.399: E/AndroidRuntime(821): FATAL EXCEPTION: main
11-30 12:46:42.399: E/AndroidRuntime(821): java.lang.NullPointerException
11-30 12:46:42.399: E/AndroidRuntime(821):  at com.example.test.Test$1$1$1.run(Test.java:63)
11-30 12:46:42.399: E/AndroidRuntime(821):  at android.os.Handler.handleCallback(Handler.java:587)
11-30 12:46:42.399: E/AndroidRuntime(821):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-30 12:46:42.399: E/AndroidRuntime(821):  at android.os.Looper.loop(Looper.java:123)
11-30 12:46:42.399: E/AndroidRuntime(821):  at android.app.ActivityThread.main(ActivityThread.java:3683)
11-30 12:46:42.399: E/AndroidRuntime(821):  at java.lang.reflect.Method.invokeNative(Native Method)
11-30 12:46:42.399: E/AndroidRuntime(821):  at java.lang.reflect.Method.invoke(Method.java:507)
11-30 12:46:42.399: E/AndroidRuntime(821):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-30 12:46:42.399: E/AndroidRuntime(821):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-30 12:46:42.399: E/AndroidRuntime(821):  at dalvik.system.NativeStart.main(Native Method)

and here is my test class
Test.java

package com.example.test;

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 java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.AutoCompleteTextView;
import android.widget.Button;

public class Test extends Activity {

    AutoCompleteTextView acw;
    Button click;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy); 

        acw=(AutoCompleteTextView)findViewById(R.id.AndroidBooks);
        click=(Button)findViewById(R.id.button1);

        final Handler threadHandler;  
        threadHandler = new Handler();

        new Thread(new Runnable(){

            @Override
            public void run() {

                final String url="http://10.0.2.2:3325/api/ProductType";

                click.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        threadHandler.post(new Runnable(){

                            @Override
                            public void run() {

                                List<String> temp=new ArrayList<String>();

                                try {
                                    JSONObject json=executeGet(url);
                                    Log.v("Response", json.toString());
                                } catch (JSONException e) {

                                    e.printStackTrace();
                                }

                            }

                        });

                    }
                });

            }

        }).start();
    }

    public static JSONObject  executeGet(String url) throws JSONException
    {
        InputStream is = null;
        String result = "";
        JSONObject jArray = null;
        int response=0;
        HttpURLConnection connection = null; 
        try
        {
            connection = (HttpURLConnection) new URL(url).openConnection();
            connection.setDoInput(true);
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestMethod("GET");
            connection.connect();
            response=connection.getResponseCode();
            is=connection.getInputStream();
        } 
        catch(Exception e)
        {
            e.printStackTrace();
            Log.e("HTTP Response", e.toString());
        }
        try
        {
            if(response==200)
            {

                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;

                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                } 
                is.close();
                result=sb.toString();

                jArray = new JSONObject(result);
            }

        }
        catch (IOException e) {
            e.printStackTrace();
        }
        catch(Exception e)
        {
            Log.e("log_tag", "Error converting result "+e.toString());
        }

        return jArray;
    }

}

I find on google that data isn`t JSON format. according to my log my data is in JSON format. so whats wrong in the code. i also use UTF-8 encoding. but same issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:53:16+00:00Added an answer on June 15, 2026 at 8:53 am

    You are trying to convert JsonArray to JsonObject so change your code as because in current json string contain an JsonArray instead of JsonObejct as root element:

     try {
          JSONArray jsonarray=executeGet(url);
          for (int i = 0; i < jsonarray.length(); ++i) {
          JSONObject jsonobject = jsonarray.getJSONObject(i);
          String str_name=jsonobject.getString("Name");
          String str_Batch=jsonobject.getString("Batch");
          String str_Id=jsonobject.getString("Id");
          String str_Expiry=jsonobject.getString("Expiry");
          String str_Type=jsonobject.getString("Type");
          String str_Price=jsonobject.getString("Price");
    
          } catch (JSONException e) {
             e.printStackTrace();
        }
    

    and also change retrun type of executeGet(String url) method from JsonObject to JSONArray as

    public static JSONArray executeGet(String url) throws JSONException
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some internal-facing ASP.NET web services that have had numerous API additions over
I have web services built with ASP.NET and ASP.NET clients consuming them. When consuming
I have developed a web application in asp.net 3.5. It is consuming lot of
This is my first time consuming a SOAP web service in ASP.Net and I
I have an ASP.NET MVC4 website implementing a REST API, which I'm consuming from
I am new to ASP.Net MVC and ASP.Net web api. I have worked on
I am using ASP.NET Web Api and one of the methods is exposed as
I'm consuming a third-party web service in an ASP.NET webforms application. I simply added
I have a WCF ASP.Net 4.0 web service we'll call WebService. WebService is consuming
I am creating a web based email client using c# asp.net. What is confusing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.