方法makeHttpRequest(String,String,List <namevaluepair>)未定义类型JSONParser </namevaluepair>

时间:2014-09-22 13:36:08

标签: android

我想在android中的mysql数据库中插入数据。我已为它编写代码,但它显示错误 方法makeHttpRequest(String,String,List)未定义类型JSONParser

我尝试了很多但没有得到解决方案。以下是我的代码

package com.example.restoapp;

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

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

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

public class PDetails extends Activity {

    public SharedPreferences PDetails;
    String name,phno,mydate,Beverages,Buffet, Starters,Family,Friends,Office,Someone,Others1,Redio,SMS,News,Email,FB,Others2,Attentive,Speed, Booking,Q2,Q4;
     private static String url_create_product = "http://abcCode/insertdata.php";

        // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private ProgressDialog pDialog;
    JSONParser jsonParser = new JSONParser();





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pdetails);

    }


    public void Finish(View view)
    {

        mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
        EditText name1=(EditText)findViewById(R.id.editText1);
        EditText phno1=(EditText)findViewById(R.id.editText2);

        name=name1.getText().toString();
        phno=phno1.getText().toString();

        SharedPreferences settings1 = getSharedPreferences("MyPref1",Context.MODE_PRIVATE);
         Beverages = settings1.getString("Beverages", "");
         Buffet = settings1.getString("Buffet", "");
         Starters = settings1.getString("Starters", "");



        SharedPreferences settings2 = getSharedPreferences("MyPref2",Context.MODE_PRIVATE);
         Attentive = settings2.getString("Attentive", "");
         Speed = settings2.getString("Speed", "");
         Booking = settings2.getString("Booking", "");




        SharedPreferences settings3 = getSharedPreferences("MyPref3",Context.MODE_PRIVATE);
         Q2 = settings3.getString("Q2", "");
         Family = settings3.getString("Family", "");
         Friends = settings3.getString("Friends", "");
         Office = settings3.getString("Office", "");
         Someone = settings3.getString("Someone", "");
         Others1 = settings3.getString("Others", "");



        SharedPreferences settings4 = getSharedPreferences("MyPref4",Context.MODE_PRIVATE);
         Q4 = settings4.getString("Q4", "");
         Redio = settings4.getString("Redio", "");
         SMS = settings4.getString("SMS", "");
         News = settings4.getString("News", "");
         Email = settings4.getString("Email", "");
         FB = settings4.getString("FB", "");
        Others2 = settings4.getString("Others", "");


        new CreateNewProduct().execute();   

    }


    /**
     * Background Async Task to Create new product
     * */
    class CreateNewProduct extends AsyncTask<String, String, String>
    {

        JSONObject json;
        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(PDetails.this);
            pDialog.setMessage("Creating Product..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();

            params.add(new BasicNameValuePair("name", name));
            params.add(new BasicNameValuePair("phno", phno));
            params.add(new BasicNameValuePair("date1", mydate));    




            // getting JSON Object
            // Note that create product url accepts POST method
            json = jsonParser.makeHttpRequest(url_create_product,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created product
                    Intent i = new Intent(getApplicationContext(), Thank.class);
                    startActivity(i);

                    // closing this screen
                    finish();
                } else {
                    // failed to create product
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            pDialog.dismiss();
        }

    }

}

1 个答案:

答案 0 :(得分:1)

它没有这样的方法indeed。您可以使用HttpClient发出http请求,请查看tutorial