HTTPClient Example - Exception in thread “main” java.lang.NoSuchFieldError: INSTANCE

后端 未结 8 817
孤城傲影
孤城傲影 2020-11-29 10:22

I am using HttpClient components from Apache for the following simple program and I see the below exception:

Exception in thread \"main\" java.lang.NoSuchFieldErr         


        
8条回答
  •  情话喂你
    2020-11-29 10:37

    This code works...without any error.. check the packages if you are using similar import .

    package com.jai.http;
    
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.impl.client.HttpClientBuilder;
    
    public class HttpExample {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            HttpClient client = HttpClientBuilder.create().build();
            HttpGet request = new HttpGet("https://www.google.com/?q=java");
            try {
                HttpResponse response = client.execute(request);
                System.out.println(response.getStatusLine());
    
            } catch (Exception e) {
                e.printStackTrace();
    
            }
    
        }
    }
    

提交回复
热议问题