Skip to content
Advertisement

My variable syntax is turning blue in eclipse which leads to errors in code [closed]

I’m just working on a project and I have to use eclipse to work on it. So, when I was creating a for loop, I had noticed that the ‘i’ variable had just turned blue and it returned the same Syntax error from the previous code which was Syntax error on token ";", , expected. Here are the images to show you what I mean.

First case

Second Case

I haven’t really changed anything in Eclipse settings recently or in general concerning syntax. I have no idea why it’s being weird. I also found that when I hover over ‘i’, it shows int activities.activity1.Card.i.

Advertisement

Answer

You are writing code directly inside a class. Any code that should be excuted is written inside a method.

In your case,

public class Cards {
    //this is inside class.
    for(int i=0; i<4; i++) { /*Your code*/ }
}

Change this to:

public class Cards {
    public static void main(String[] args) {
        for(int i=0; i<4; i++) { /*Your code*/ }
    }
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement