I'm getting this weird compilation error with eclipse in the following code block. I've included the necessary jars and also tried restarting eclipse but no avail.
public class ControlServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
ResourceBundle rb1;// error on this line
rb1 = ResourceBundle.getBundle("connection_config");
Logger log = LoggerFactory.getLogger(ControlServlet.class);
The error message displayed is:
Multiple markers at this line
- Syntax error on token ";", , expected
- Watchpoint:ControlServlet [access and
modification] - rb1.
Any idea why this could be happening ? And how I could work around this would be helpful.
You are getting this error because you can not write assignment statement and declaration as 2 statements in a class (outside of any method or static block with class variables).
So your error is actually on this statement:
rb1 = ResourceBundle.getBundle("connection_config");
You can not write such a statement in class without surrounding static/method block. cannot write outside of any method or any initialization block (static or non-static). So you have to combine your 2 statements into 1 like:
ResourceBundle rb1 = ResourceBundle.getBundle("connection_config");
You may have to replace this
ResourceBundle rb1;// error on this line
rb1 = ResourceBundle.getBundle("connection_config");
with this
ResourceBundle rb1 = ResourceBundle.getBundle("connection_config");
In Java, we can only have variable declaration statements, an initialization block(static and non-static), and method defintions inside a class directly. All other statements like assignment statements, control statements, etc., must be inside an initialization block or inside a method definition.
Here, rb1 = ResourceBundle.getBundle("connection_config"); is an assignment statement, which is not permitted to put directly inside a class. That is why, we have to combine the declaration, and assignment statements to one like ResourceBundle rb1 = ResourceBundle.getBundle("connection_config");.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With