简体   繁体   中英

while parsing data in json getting error java.lang.nullpointerexception & end of input character at 0

this is my service code. please help me to get rid from` this. i call this service on button click . but getting this error every time.thanks in advance. also check the link to webservices don't know is it correct or not

package com.ballerxtreme;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;

public class Send_request_id extends AsyncTask<String, String, JSONObject> {
    Activity activity;
    String request_id;
    JSONParser jp = new JSONParser();

    public Send_request_id(Activity activity, String request_id) {
        this.activity = activity;
        this.request_id = request_id;
    }

    @Override
    protected void onPreExecute() {     
        super.onPreExecute();
    }

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

        String url = "http://jstarfitness.com/service/saveuser.php";
        // String url = "http://jstarfitness.com/service/index.php";
        JSONParser parser = new JSONParser();

        List<NameValuePair> param = new ArrayList<NameValuePair>();
        param.add(new BasicNameValuePair("requestid", request_id));
        String json_send = parser.makeHttpRequest(url, "post", param);
        JSONObject jobj = null;
        try {
            Log.e("Request-Id-Send", json_send);

            jobj = new JSONObject(json_send);

        } catch (JSONException e) {

            Log.e("Request-Id-Send", json_send);
            e.printStackTrace();
            String io = e.getMessage();

            Log.e("error", io);

        }
        return jobj;
    }

    @Override
    protected void onPostExecute(JSONObject result) {
        // TODO Auto-generated method stub
        Log.e("Id_Send", request_id);
        super.onPostExecute(result);
    }

}

I got solution from the above comments by make changes in the jsonparser class. changes in the post method now data is sent to link successfull... thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM