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

前端 未结 4 1808
清歌不尽
清歌不尽 2020-12-08 02:08
import java.awt.List;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.I         


        
相关标签:
4条回答
  • 2020-12-08 02:18

    Try to import

    java.util.List;
    

    instead of

    java.awt.List;
    
    0 讨论(0)
  • 2020-12-08 02:19

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

    0 讨论(0)
  • 2020-12-08 02:22

    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);
    
    0 讨论(0)
  • 2020-12-08 02:23

    Your import has a subtle error:

    import java.awt.List;
    

    It should be:

    import java.util.List;
    

    The problem is that both awt and Java's util package provide a class called List. The former is a display element, the latter is a generic type used with collections. Furthermore, java.util.ArrayList extends java.util.List, not java.awt.List so if it wasn't for the generics, it would have still been a problem.

    Edit: (to address further questions given by OP) As an answer to your comment, it seems that there is anther subtle import issue.

    import org.omg.DynamicAny.NameValuePair;
    

    should be

    import org.apache.http.NameValuePair
    

    nameValuePairs now uses the correct generic type parameter, the generic argument for new UrlEncodedFormEntity, which is List<? extends NameValuePair>, becomes valid, since your NameValuePair is now the same as their NameValuePair. Before, org.omg.DynamicAny.NameValuePair did not extend org.apache.http.NameValuePair and the shortened type name NameValuePair evaluated to org.omg... in your file, but org.apache... in their code.

    0 讨论(0)
提交回复
热议问题