猿问

来自androidhive教程的JSONParser,DefaultHttpClient

我正在遵循本教程,并遇到此错误:


Caused by: java.lang.NoSuchMethodError: No virtual method execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/client/methods/CloseableHttpResponse; in class Lorg/apache/http/impl/client/DefaultHttpClient; or its super classes (declaration of 'org.apache.http.impl.client.DefaultHttpClient' appears in /system/framework/ext.jar)

                at info.androidhive.materialtabs.adpater.JSONParser.makeHttpRequest(JSONParser.java:52)

                at info.androidhive.materialtabs.UserFunctions.loginUser(UserFunctions.java:37)

                at info.androidhive.materialtabs.activity.MainActivity$Login.doInBackground(MainActivity.java:551)

                at info.androidhive.materialtabs.activity.MainActivity$Login.doInBackground(MainActivity.java:519)

这是我正在使用的JSONParser类:


public class JSONParser {

     static InputStream is = null;

        static JSONObject jObj = null;

        static String json = "";

        // constructor

        public JSONParser() {

        }

        // function get json from url

        // by making HTTP POST or GET method

        public JSONObject makeHttpRequest(String url, String method,

                List<NameValuePair> params) {

            // Making HTTP request

            try {

                // check for request method

                if(method == "POST"){

                    // request method is POST

                    // defaultHttpClient

                    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();

                }


波斯汪
浏览 619回答 2
2回答

慕无忌1623718

错误:(74,37)错误:类JSONParser中的方法makeHttpRequest无法应用于给定类型;必需:String,String,HashMap <String,String>找到:String,String,List <NameValuePair>原因:实际参数List <NameValuePair>不能通过方法调用转换转换为HashMap <String,String>
随时随地看视频慕课网APP

相关分类

Java
Android
我要回答