[java] The type List is not generic; it cannot be parameterized with arguments [HTTPClient]

import java.awt.List;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;

import javax.imageio.ImageIO;

import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.omg.DynamicAny.NameValuePair;

public class Upload {

    public static void main (String[] args) {

        System.out.println(Imgur("C:\\Users\\username\\Desktop\\image.jpg",     "clientID"));
    }

public static String Imgur (String imageDir, String clientID) {
    //create needed strings
    String address = "https://api.imgur.com/3/image";

    //Create HTTPClient and post
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(address);

    //create base64 image
    BufferedImage image = null;
    File file = new File(imageDir);

    try {
        //read image
        image = ImageIO.read(file);
        ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
        ImageIO.write(image, "png", byteArray);
        byte[] byteImage = byteArray.toByteArray();
        String dataImage = new Base64().encodeAsString(byteImage);

        //add header
        post.addHeader("Authorization", "Client-ID" + clientID);
        //add image
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("image", dataImage));
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        //execute
        HttpResponse response = client.execute(post);

        //read response
        BufferedReader rd = new BufferedReader(new         InputStreamReader(response.getEntity().getContent()));
        String all = null;

        //loop through response
        while (rd.readLine() != null) {
            all = all + " : " + rd.readLine(); 
        }

        return all;

    }
    catch (Exception e){
        return "error: " + e.toString();
    }
}
}

So I have that code and I got it from uploading to Imgur v3 using Java https errors and I get an error on line 50 for "List" telling me

The type List is not generic; it cannot be parameterized with arguments

What can I do to solve this?

I'm using http://hc.apache.org/httpclient-3.x/ and want to upload an image to imgur using their v3 API.

EDIT: After changing the import I now get these errors.

That solves that but give me two more errors.

nameValuePairs.add(new BasicNameValuePair("image", dataImage));

The method add(NameValuePair) in the type List is not applicable for the arguments (BasicNameValuePair)

And

post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

The constructor UrlEncodedFormEntity(List) is undefined

This question is related to java api httpclient imgur

The answer is


Try to import

java.util.List;

instead of

java.awt.List;

I got the same error, but when i did as below, it resolved the issue.
Instead of writing like this:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

use the below one:

ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

Adding java.util.list will resolve your problem because List interface which you are trying to use is part of java.util.list package.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to api

I am receiving warning in Facebook Application using PHP SDK Couldn't process file resx due to its being in the Internet or Restricted zone or having the mark of the web on the file Failed to load resource: the server responded with a status of 404 (Not Found) css Call another rest api from my server in Spring-Boot How to send custom headers with requests in Swagger UI? This page didn't load Google Maps correctly. See the JavaScript console for technical details How can I send a Firebase Cloud Messaging notification without use the Firebase Console? Allow Access-Control-Allow-Origin header using HTML5 fetch API How to send an HTTP request with a header parameter? Laravel 5.1 API Enable Cors

Examples related to httpclient

How to add Apache HTTP API (legacy) as compile-time dependency to build.grade for Android M? PHP GuzzleHttp. How to make a post request with params? C#: HttpClient with POST parameters How to send a Post body in the HttpClient request in Windows Phone 8? The type List is not generic; it cannot be parameterized with arguments [HTTPClient] How to add,set and get Header in request of HttpClient? No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'text/plain' SSL "Peer Not Authenticated" error with HttpClient 4.1 Apache HttpClient Interim Error: NoHttpResponseException Common HTTPclient and proxy

Examples related to imgur

The type List is not generic; it cannot be parameterized with arguments [HTTPClient]