Results 1 to 3 of 3
  1. #1
    guerlando is offline Member
    Join Date
    Mar 2016
    Posts
    11
    Rep Power
    0

    Default error: class, interface, or enum expected in simple class declaration

    I just wrote this piece of code to POST some data via HTTPs, with support for cookies. It's simple.


    Java Code:
    import java.net.URL;
    import java.io.*;
    import javax.net.ssl.HttpsURLConnection;
    //import org.jsoup.*;
    import java.net.URLEncoder;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.List;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    
    //Just a Class designed to facilitate requests to Unesp's Sisgrad server
    //
    
    //System.setProperty("jsse.enableSNIExtension", "false"); CONSERTAR ESTE PROBLEMA
    public Class SimpleRequest {
     public static String response;
     public static String responseCode;
     public static String responseMessage;
     public static String location;
     public static List < String > cookies;
    
     public SimpleRequest(String url, String postQuery, List < String > rcookies) throws Exception {
      URL myurl = new URL(url);
      HttpsURLConnection con = (HttpsURLConnection) myurl.openConnection();
      con.setInstanceFollowRedirects(false);
      con.setRequestProperty("Content-length", String.valueOf(postQuery.length()));
      con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)");
      con.setDoOutput(true);
      con.setDoInput(true);
      if (rcookies != null) {
       for (String cookie: rcookies) {
        con.addRequestProperty("Cookie", cookie.split(";", 2)[0]);
       }
      }
      if (postQuery != null) {
       con.setRequestMethod("POST");
       DataOutputStream output = new DataOutputStream(con.getOutputStream());
       output.writeBytes(postQuery);
       output.close();
      }
    
      //DataInputStream dis = new DataInputStream( con.getInputStream() ); 
      String charset = "ISO-8859-1";
      BufferedReader buff = new BufferedReader(
       new InputStreamReader(con.getInputStream(), charset));
      String response = "";
      String line;
      while ((line = buff.readLine()) != null) {
       response += line + "\n";
      }
    
      //use inputLine.toString(); here it would have whole source
      //String response = inputLine.toString();
    
      this.cookies = con.getHeaderFields().get("Set-Cookie");
      this.responseCode = Integer.toString(con.getResponseCode());
      //List<String> location = new List<String>();
      this.String responseMessage = con.getResponseMessage();
      if (responseCode.equals("302")) {
       this.location = con.getHeaderFields().get("Location").get(0);
      }
     }
    }


    When I compile, I get a LOT of errors:

    Java Code:
    error: class, interface, or enum expected                                                                                           
    public Class SimpleRequest {                                                                                                                               
           ^                                                                                                                                                   
    SimpleRequest.java:18: error: class, interface, or enum expected                                                                                           
     public static String response;                                                                                                                            
                   ^                                                                                                                                           
    SimpleRequest.java:19: error: class, interface, or enum expected                                                                                           
     public static String responseCode;                                                                                                                        
                   ^                                                                                                                                           
    SimpleRequest.java:20: error: class, interface, or enum expected                                                                                           
     public static String responseMessage;                                                                                                                     
                   ^                                                                                                                                           
    SimpleRequest.java:21: error: class, interface, or enum expected                                                                                           
     public static String location;                                                                                                                            
                   ^                                                                                                                                           
    SimpleRequest.java:22: error: class, interface, or enum expected                                                                                           
     public static List < String > cookies;                                                                                                                    
                   ^
    I've already searched this on the internet but this is a too generic error and I don't really have an idea of where the problem is, but I feel that it's SIMPLE

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: error: class, interface, or enum expected in simple class declaration

    The first error is that it should be "class" and not "Class" in your declaration. The other errors may go away when you correct that.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Sizzlewump's Avatar
    Sizzlewump is offline Member
    Join Date
    Oct 2010
    Location
    MI, USA
    Posts
    68
    Rep Power
    0

    Default Re: error: class, interface, or enum expected in simple class declaration

    For starters, use lower case 'c' for class.
    "The secret to getting what you want is to reject everything that you don't want." -Wolbers

Similar Threads

  1. Replies: 1
    Last Post: 05-15-2013, 08:00 AM
  2. Replies: 3
    Last Post: 01-20-2013, 08:06 PM
  3. Replies: 1
    Last Post: 10-03-2012, 09:38 PM
  4. class interface or enum expected Imports java.io.*; error
    By prathamkool in forum New To Java
    Replies: 2
    Last Post: 10-02-2011, 04:53 PM
  5. Replies: 2
    Last Post: 10-02-2010, 02:13 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •