Search code examples
javaintellij-idea

error:missing package statement 'src' but still can run the code in IntelliJ


I'm new to Java, I created a repo in Gitlab and imported to IntelliJ, it's a new repo so nothing in the folder now. I created a folder 'src' manually on my machine and created a java file.

public class Test{
  public static void main(String[] args)
  {
    System.out.println("This is a test!");
  }

}

The code works fine, but the first line under 'Test' there's a curvy red line, normally if I create a new project in IntelliJ, I won't have this kind of problem, is it because I can't create 'src' folder manually? How can I fix this? enter image description here


Solution

  • try to mark the folder src you created as source in: File->project structure->Modules