Checkstyle : always receive File contains tab characters (this is the first instance)

hqt picture hqt · Aug 30, 2012 · Viewed 56.7k times · Source

I'm using Checkstyle for Java in Eclipse IDE. I don't know in every java file, at second line, I always receive warning in Checkstyle : (although I'm pretty sure that I don't press tab key)

File contains tab characters (this is the first instance).

public class Percolation {
    private boolean[][] grid;
...
}

When I have typed : public class Percolation {, press enter, Eclipse will make an indent for me, after that, I type private boolean[][] grid;. But, I still receive this warning.

Please tell me how to fix this. (I don't want to turn off this warning, because this is a must. Another people will check again my file).

Thanks :)

Answer

JToddler picture JToddler · Oct 22, 2012

step 1 In eclipse, Preference > Java > Code Style > Formatter. Edit the Active profile.(If you don't wish to edit the built-in profile , create a new profile). Under "Active profile:" there is a drop down dialogue box .. beside it, click "Edit..." which opens up the edit dialog box. Under the "Indention" tab, you'll find Tab Policy. Change the Tab Policy from Mixed to Space only & apply the changes.

step 2 Back to your Eclipse Perspective, navigate via the menu bar: Source > Format Element (not "Format") and save.

Run checkstyle you won't find "File Tab Character: File contains tab characters (this is the first instance)." warning anymore.

To visualize the difference by enabling whitespace character that you'll find in tool bar.