1

So I am attempting to use Apache Commons in Android, and I am getting a VerifyError. I have the httpclient-4.5.1 library imported into my External Jars in my build path. When I run it, I am getting a VerifyError:

VerifyError from LogCat

This is my code; it crashes on the first line of code:

CloseableHttpClient httpClient = HttpClientBuilder.create().build();

    try {
        HttpPost url= new HttpPost("http://192.168.10.2:8080/iNSIGHTJSON");
        StringEntity parameter = new StringEntity("{ \"getNewWifi\" : [ 0 ] }");
        url.addHeader("content-type", "a" + "pplicati" + "on/json");
        url.setEntity(parameter);
        httpClient.execute(url);

        ResponseHandler<String> responseHandler=new BasicResponseHandler();
        String responseBody = httpClient.execute(url, responseHandler);

        JSONObject response=new JSONObject(responseBody);
        Log.d("json object", responseBody);

        RunWifiAnalysis.this.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                ((SmartCpeAtt) getActivity()).switchTabSet(R.id.wifi0, 1);
            }
        });
    // handle response here...
    } catch (Exception ex) {
        // handle exception here
    }

Is this just an Android issue, or am I doing something wrong? The code works on a blank Java project, but does for Android. Is the library not compatible? If so, what is something similar I can use that is compatible and does what I want it to?

  • You should have a look at this question: http://stackoverflow.com/questions/100107/reasons-of-getting-a-java-lang-verifyerror . – Shlublu Oct 27 '15 at 17:04
  • 1
    The top answer didn't really provide a solution; I looked at some of the others, and one said to import a library. How would I do that with the HttpClient jar file? – Ashwin Sundar Oct 27 '15 at 17:17
  • I think the issue comes from the fact the HttpClient exists in both the lib you imported and Android (depending on the plateform you are using it may have been withdrawn from the regular libs and only accessible using a specific build option though). Do you absolutely need to use apache.commons, and not the built-in Apche HttpClient, or even better, URLConnection? – Shlublu Oct 27 '15 at 17:21
  • I decided to use URLConnection, and it seems to be working. I just wonder what exactly is a VerifyError haha – Ashwin Sundar Oct 27 '15 at 20:39
  • The VerifyError occurs when the code does not correspond to the actually linked lib for a given object. The question I linked above summarizes and explains that perfectly. – Shlublu Oct 28 '15 at 01:16

0 Answers0