java – Syntax error on token(s), misplaced construct(s)

java – Syntax error on token(s), misplaced construct(s)

You need to place all statements after the declarations in a code block, e.g. method rather than the class block. Logically it probably makes sense to place all statements in the code block but the non-declarative statements need to be enclosed within the new block

private void processFile() {
    data.put(1, new Object[]{ID,NAME, LASTNAME}); // <--Syntax error  
     ...//snip
  } catch (Exception e) {
     e.printStackTrace();
  } 
}

Issue resolved. I created a new project in Eclipse, added the POI (jar) to the libraries and the syntax error is no longer displayed.

java – Syntax error on token(s), misplaced construct(s)

Place all of your code within a main method:

public static void main(String[] args) {
        //All of your code goes here

}

Statements (this does not include declarations) must be executed inside a block. It appears that you are conducting a test of some code and that this is not meant to be an actual object in your code, so you must place it within the main method.

Leave a Reply

Your email address will not be published.