Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何解决这个有makeHttpRequest错误的错误?_Java_Android_Json - Fatal编程技术网

Java 如何解决这个有makeHttpRequest错误的错误?

Java 如何解决这个有makeHttpRequest错误的错误?,java,android,json,Java,Android,Json,我有一个错误: Error:(102, 53) error: cannot find symbol method makeHttpRequest(String,String,List<NameValuePair>) 错误:(102,53)错误:找不到符号方法makeHttpRequest(字符串,字符串,列表) 即使尝试了我所知道的一切,我似乎也无法消除。。请帮忙。。先谢谢你 这是活动代码: EditProductActivity.java: package com.examp

我有一个错误:

Error:(102, 53) error: cannot find symbol method  makeHttpRequest(String,String,List<NameValuePair>)
错误:(102,53)错误:找不到符号方法makeHttpRequest(字符串,字符串,列表)
即使尝试了我所知道的一切,我似乎也无法消除。。请帮忙。。先谢谢你

这是活动代码:

EditProductActivity.java:

package com.example.vikrant.testingv3;
import java.util.ArrayList;    
import java.util.List;    
import java.io.BufferedReader;    
import java.io.DataOutputStream;   
import java.io.InputStreamReader;    
import java.net.HttpURLConnection;   
import java.net.URL;   
import org.apache.http.NameValuePair;   
import org.apache.http.message.BasicNameValuePair;   
import org.json.JSONArray;   
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.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log; 
import android.view.View;
import android.widget.Button;  
import android.widget.EditText;

public class EditProductActivity extends Activity{

    EditText txtName;
    EditText txtPrice;
    EditText txtDesc;
    EditText txtCreatedAt;
    Button btnSave;
    Button btnDelete;

    String pid;
    private ProgressDialog pDialog;
    JSONParser jsonParser = new JSONParser();

    private static final String url_product_detials = "http://localhost/android_connect/get_product_details.php";

    private static final String url_update_product = "http://localhost/android_connect/update_product.php";

    private static final String url_delete_product = "http://localhost/android_connect/delete_product.php";

    private static final String TAG_SUCCESS = "success";
    private static final String TAG_PRODUCT = "product";
    private static final String TAG_PID = "pid";
    private static final String TAG_NAME = "name";
    private static final String TAG_PRICE = "price";
    private static final String TAG_DESCRIPTION = "description";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_product);
        btnSave = (Button) findViewById(R.id.btnSave);
        btnDelete = (Button) findViewById(R.id.btnDelete);
        Intent i = getIntent();
        pid = i.getStringExtra(TAG_PID);
        new GetProductDetails().execute();
        btnSave.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                new SaveProductDetails().execute();
            }
        });
        btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                new DeleteProduct().execute();
            }
        });
    }





    class GetProductDetails extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(EditProductActivity.this);
            pDialog.setMessage("Loading product details. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        protected String doInBackground(String... params) {
            runOnUiThread(new Runnable() {
                public void run() {
                    int success;
                    try {
                        List<NameValuePair> params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("pid", pid));

                        JSONObject json = jsonParser.makeHttpRequest(url_product_detials, "GET", params);

                        Log.d("Single Product Details", json.toString());
                        success = json.getInt(TAG_SUCCESS);
                        if (success == 1) {
                            JSONArray productObj = json
                                    .getJSONArray(TAG_PRODUCT);

                            JSONObject product = productObj.getJSONObject(0);


                            txtName = (EditText) findViewById(R.id.inputName);
                            txtPrice = (EditText) findViewById(R.id.inputPrice);
                            txtDesc = (EditText) findViewById(R.id.inputDesc);


                            txtName.setText(product.getString(TAG_NAME));
                            txtPrice.setText(product.getString(TAG_PRICE));
                            txtDesc.setText(product.getString(TAG_DESCRIPTION));

                        }else{
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
            return null;
        }
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once got all details
            pDialog.dismiss();
        }
    }

    class SaveProductDetails extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(EditProductActivity.this);
            pDialog.setMessage("Saving product ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }


        protected String doInBackground(String... args) {
            String name = txtName.getText().toString();
            String price = txtPrice.getText().toString();
            String description = txtDesc.getText().toString();

            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair(TAG_PID, pid));
            params.add(new BasicNameValuePair(TAG_NAME, name));
            params.add(new BasicNameValuePair(TAG_PRICE, price));
            params.add(new BasicNameValuePair(TAG_DESCRIPTION, description));

            JSONObject json = jsonParser.makeHttpRequest(url_update_product, "POST", params);
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    Intent i = getIntent();
                    setResult(100, i);
                    finish();
                } else {
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once product uupdated
            pDialog.dismiss();
        }
    }

    class DeleteProduct extends AsyncTask<String, String, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(EditProductActivity.this);
            pDialog.setMessage("Deleting Product...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }


        protected String doInBackground(String... args) {
            int success;
            try {
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("pid", pid));

                JSONObject json = jsonParser.makeHttpRequest(url_delete_product, "POST", params);
                Log.d("Delete Product", json.toString());
                success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    Intent i = getIntent();
                    setResult(100, i);
                    finish();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once product deleted
            pDialog.dismiss();
        }
    }
}
package com.example.vikrant.testingv3;
导入java.util.ArrayList;
导入java.util.List;
导入java.io.BufferedReader;
导入java.io.DataOutputStream;
导入java.io.InputStreamReader;
导入java.net.HttpURLConnection;
导入java.net.URL;
导入org.apache.http.NameValuePair;
导入org.apache.http.message.BasicNameValuePair;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入org.json.simple.parser.JSONParser;
导入android.app.Activity;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
公共类EditProductActivity扩展了活动{
编辑文本txtName;
编辑文本txtPrice;
编辑文本txtDesc;
编辑文本txtCreatedAt;
按钮btnSave;
按钮btnDelete;
串pid;
私人对话;
JSONParser JSONParser=新的JSONParser();
私有静态最终字符串url\u product\u detials=”http://localhost/android_connect/get_product_details.php";
私有静态最终字符串url\u更新\u产品=”http://localhost/android_connect/update_product.php";
私有静态最终字符串url\u delete\u product=”http://localhost/android_connect/delete_product.php";
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
私有静态最终字符串TAG_PRODUCT=“PRODUCT”;
私有静态最终字符串标记_PID=“PID”;
私有静态最终字符串标记_NAME=“NAME”;
私有静态最终字符串标记_PRICE=“PRICE”;
私有静态最终字符串标记_DESCRIPTION=“DESCRIPTION”;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_产品);
btnSave=(按钮)findviewbyd(R.id.btnSave);
btnDelete=(按钮)findViewById(R.id.btnDelete);
Intent i=getIntent();
pid=i.getStringExtra(标签\ pid);
新建GetProductDetails().execute();
btnSave.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
新建SaveProductDetails().execute();
}
});
btnDelete.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图arg0){
新的DeleteProduct().execute();
}
});
}
类GetProductDetails扩展了AsyncTask{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=newprogressdialog(EditProductActivity.this);
pDialog.setMessage(“正在加载产品详细信息。请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
受保护的字符串doInBackground(字符串…参数){
runOnUiThread(新的Runnable(){
公开募捐{
成功;
试一试{
List params=new ArrayList();
参数添加(新的BasicNameValuePair(“pid”,pid));
JSONObject json=jsonParser.makeHttpRequest(url_product_detials,“GET”,params);
Log.d(“单一产品详细信息”,json.toString());
success=json.getInt(TAG_success);
如果(成功==1){
JSONArray productObj=json
.getJSONArray(TAG_产品);
JSONObject product=productObj.getJSONObject(0);
txtName=(EditText)findViewById(R.id.inputName);
txtPrice=(EditText)findViewById(R.id.inputPrice);
txtDesc=(EditText)findViewById(R.id.inputDesc);
setText(product.getString(TAG_NAME));
setText(product.getString(TAG_PRICE));
txtDesc.setText(product.getString(TAG_DESCRIPTION));
}否则{
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
});
返回null;
}
受保护的void onPostExecute(字符串文件\u url){
//获得所有详细信息后关闭对话框
pDialog.disclose();
}
}
类SaveProductDetails扩展了异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=newprogressdialog(EditProductActivity.this);
pDialog.setMessage(“保存产品…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
受保护的字符串doInBackground(字符串…args){
字符串名称=txtName.getText().toString();
字符串price=txtPrice.getText().toString();
字符串描述=txtDesc.getText().toString();
List params=new ArrayList();
参数添加(新的BasicNameValuePair(TAG_PID,PID));
参数添加(新的BasicNameValuePair(标记名称,名称));
参数添加(新的BasicNameValuePair(标签价格,价格));
参数添加(新的BasicNameValuePair(标记描述,描述));
JSONObject json=jsonParser.makeHttpRequest(url\u update\u product,“POS
 package com.example.vikrant.testingv3;

import java.io.BufferedReader;    
import java.io.IOException;  
import java.io.InputStream;    
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;    
import java.util.List;    
import java.io.BufferedReader;    
import java.io.DataOutputStream;  
import java.io.InputStreamReader;   
import java.net.HttpURLConnection;  
import java.net.URL;   
import javax.net.ssl.HttpsURLConnection; 
import org.apache.http.HttpEntity;   
import org.apache.http.HttpResponse; 
import org.apache.http.NameValuePair;   
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.entity.UrlEncodedFormEntity;   
import org.apache.http.client.methods.HttpGet;   
import org.apache.http.client.methods.HttpPost;  
import org.apache.http.client.utils.URLEncodedUtils;    
import org.apache.http.impl.client.DefaultHttpClient;  
import org.json.JSONException;  
import org.json.JSONObject;    
import org.json.JSONArray;  
import android.util.Log;

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    public JSONParser() {
    }
    public JSONObject makeHttpRequest(String url, String method, List<NameValuePair> params) {
        try {
            if(method == "POST"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new UrlEncodedFormEntity(params));

                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }else if(method == "GET"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                String paramString = URLEncodedUtils.format(params, "utf-8");
                url += "?" + paramString;
                HttpGet httpGet = new HttpGet(url);

                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            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();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        return jObj;
    }
}
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;

public class JSONParser {

    String charset = "UTF-8";
    HttpURLConnection conn;
    DataOutputStream wr;
    StringBuilder result;
    URL urlObj;
    JSONObject jObj = null;
    StringBuilder sbParams;
    String paramsString;

    public JSONObject makeHttpRequest(String url, String method,
                                      HashMap<String, String> params) {

        sbParams = new StringBuilder();
        int i = 0;
        for (String key : params.keySet()) {
            try {
                if (i != 0){
                    sbParams.append("&");
                }
                sbParams.append(key).append("=")
                        .append(URLEncoder.encode(params.get(key), charset));

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            i++;
        }

        if (method.equals("POST")) {
            // request method is POST
            try {
                urlObj = new URL(url);

                conn = (HttpURLConnection) urlObj.openConnection();

                conn.setDoOutput(true);

                conn.setRequestMethod("POST");

                conn.setRequestProperty("Accept-Charset", charset);

                conn.setReadTimeout(10000);
                conn.setConnectTimeout(15000);

                conn.connect();

                paramsString = sbParams.toString();

                wr = new DataOutputStream(conn.getOutputStream());
                wr.writeBytes(paramsString);
                wr.flush();
                wr.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        else if(method.equals("GET")){
            // request method is GET

            if (sbParams.length() != 0) {
                url += "?" + sbParams.toString();
            }

            try {
                urlObj = new URL(url);

                conn = (HttpURLConnection) urlObj.openConnection();

                conn.setDoOutput(false);

                conn.setRequestMethod("GET");

                conn.setRequestProperty("Accept-Charset", charset);

                conn.setConnectTimeout(15000);

                conn.connect();

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

        }

        try {
            //Receive the response from the server
            InputStream in = new BufferedInputStream(conn.getInputStream());
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            result = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                result.append(line);
            }

            Log.d("JSON Parser", "result: " + result.toString());

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

        conn.disconnect();

        // try parse the string to a JSON object
        try {
            jObj = new JSONObject(result.toString());
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }

        // return JSON Object
        return jObj;
    }
}