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

  • Home
  • SEARCH
  • 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 7770873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:30:48+00:00 2026-06-01T16:30:48+00:00

i need help.. i’m trying to call php webservices from my android client application

  • 0

i need help.. i’m trying to call php webservices from my android client application ,and i couldn’t call it from main thread coz the SDK is 15 ,and I search on the web and I found the solution for this problem is to use the Asynktask .. but it doesn’t work with me i don’t know why .. any help please ..Thank you

public class CustomWebConnection extends AsyncTask<Void, Void, String> {
private final String                 uri = "http://localhost/mywebservices.php?op=GetAllRest";
private ArrayList<NameValuePair>     mParams;
private OnPostExecuteListener        mPostExecuteListener = null;

public static interface OnPostExecuteListener{
    void onPostExecute(String result);
}

CustomWebConnection(ArrayList<NameValuePair> nameValuePairs,
    OnPostExecuteListener postExecuteListener) throws Exception {

    mParams = nameValuePairs;
    mPostExecuteListener = postExecuteListener;
    if (mPostExecuteListener == null)
        throw new Exception("Param cannot be null.");
}

@Override
protected String doInBackground(Void... params) {

      JSONObject param=null;
      String result = null;
      HttpClient httpClient = new DefaultHttpClient();
        HttpHost httpHost = new HttpHost("localhost",80);  
        HttpPost httpPost = new HttpPost(uri);
        httpPost.addHeader("Content-Type", "application/json; charset=utf-8");


        try
        {
            //HttpEntity bodyEntity = new StringEntity(param.toString(), "utf8");
            //httpPost.setEntity(bodyEntity);
            HttpResponse response = httpClient.execute(httpPost);
            HttpEntity entity = response.getEntity();

            if (entity != null) {
                InputStream instream = entity.getContent();
                BufferedReader reader = new BufferedReader(
                     new InputStreamReader(instream));
                StringBuilder sb = new StringBuilder();


                String line = null;
                while ((line = reader.readLine()) != null)
                    sb.append(line + "\n");


                result = sb.toString();
                instream.close();           
            }
        }

        catch(Exception e)
        {
            e.printStackTrace();
        }


    httpPost.abort();
    return result ;
}

@Override
protected void onPostExecute(String result) {
    if (mPostExecuteListener != null){
        try {
            JSONObject json = new JSONObject(result);
            mPostExecuteListener.onPostExecute(result);
        } catch (JSONException e){
            e.printStackTrace();
        }
    }
} 

and it’s throw this exception

     04-09 16:31:37.393: E/AndroidRuntime(2284): FATAL EXCEPTION: main
     04-09 16:31:37.393: E/AndroidRuntime(2284): java.lang.NullPointerException
      04-09 16:31:37.393: E/AndroidRuntime(2284):   at    org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
     04-09 16:31:37.393: E/AndroidRuntime(2284):    at  org.json.JSONTokener.nextValue(JSONTokener.java:94)
      04-09 16:31:37.393: E/AndroidRuntime(2284):   at org.json.JSONObject.<init>(JSONObject.java:154)
     04-09 16:31:37.393: E/AndroidRuntime(2284):    at org.json.JSONObject.<init>(JSONObject.java:171)
  04-09 16:31:37.393: E/AndroidRuntime(2284):   at  com.vtab.CustomWebConnection.onPostExecute(CustomWebConnection.java:92)
 04-09 16:31:37.393: E/AndroidRuntime(2284):    at com.vtab.CustomWebConnection.onPostExecute(CustomWebConnection.java:1)
 04-09 16:31:37.393: E/AndroidRuntime(2284):    at  android.os.AsyncTask.finish(AsyncTask.java:602)
 04-09 16:31:37.393: E/AndroidRuntime(2284):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
 04-09 16:31:37.393: E/AndroidRuntime(2284):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
 04-09 16:31:37.393: E/AndroidRuntime(2284):    at android.os.Handler.dispatchMessage(Handler.java:99)
 04-09 16:31:37.393: E/AndroidRuntime(2284):    at android.os.Looper.loop(Looper.java:137)
  04-09 16:31:37.393: E/AndroidRuntime(2284):   at android.app.ActivityThread.main(ActivityThread.java:4424)
  04-09 16:31:37.393: E/AndroidRuntime(2284):   at java.lang.reflect.Method.invokeNative(Native Method)
  04-09 16:31:37.393: E/AndroidRuntime(2284):   at java.lang.reflect.Method.invoke(Method.java:511)
  04-09 16:31:37.393: E/AndroidRuntime(2284):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  04-09 16:31:37.393: E/AndroidRuntime(2284):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
 04-09 16:31:37.393: E/AndroidRuntime(2284):    at dalvik.system.NativeStart.main(Native Method)

the error at HttpResponse response = httpClient.execute(httpPost);

and this is the JSON response from the server

[{"rest_id":"1","rest_name":"Al Dabke","cuisine":"Lebanese","no_tables":"15","bg_img":"lebanon","rest_logo":"dabke"},{"rest_id":"4","rest_name":"MY KIND OF PLACE","cuisine":null,"no_tables":"10","bg_img":"kindofplacebg","rest_logo":"mykindofplacelogo"},{"rest_id":"5","rest_name":"LANTANIA","cuisine":"Thai","no_tables":"10","bg_img":"lantaniabg","rest_logo":"lantanialogo"},{"rest_id":"6","rest_name":"LEONARDO","cuisine":"italian","no_tables":"10","bg_img":"leonardobg","rest_logo":"leonardologo"},{"rest_id":"7","rest_name":"LE MARCHE ","cuisine":"French","no_tables":"10","bg_img":"lemarchebg","rest_logo":"lemarchelogo"},{"rest_id":"8","rest_name":"Marias","cuisine":"mexican","no_tables":"10","bg_img":"mariang","rest_logo":"marialogo"},{"rest_id":"9","rest_name":"NOBLE HOUSE","cuisine":"chinese","no_tables":"10","bg_img":"noblehousebg","rest_logo":"noblehouselogo"}]

any help please

  • 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-01T16:30:50+00:00Added an answer on June 1, 2026 at 4:30 pm

    I have also face this issue recently and i found that HttpClient is problem in Android ICS ,,, The simple hack i used is to change min SDK version to 7 from 15. But its isnt a proper solution. i come across the code from a blog

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

    Putting this in onCreate() method has solved my problem. May be it can help you. still i am looking for some more options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help with PHP/MySql. Need to select all the records from 'today'. My table
Need help with below code. I am trying to query from same table and
Need help for implementing PUSH notification in android. wanted to know from which android
need help on this, trying to upload images from IE9 I get an C:fakepath/name_of_my_file
Need help writing a script downloads data from google insight using c# this is
I need help finishing this statement. It is frustrating that two of the PHP
Need help in PDF generation because I am doing a project with PHP CodeIgniter.
I need help to rewrite URL with htaccess, now my url is http://site.com/index.php?user=ln12666279n i
Need help trying to figure out why the button onCLick event isn't working. I
Need help with my simple PHP menu. I'd like to have something like that:

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.