Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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*/ }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading