Accepted answer

just go into the build path and change the source path to be src/prefix1 instead of src.

it may be easiest to right-click on the src directory and select "build path / remove from build path", then find the src/prefix1 directory, right-click it and select "build path / use as source folder".


  1. right click on the external folder which is having package
  1. click build path --> remove from build path.

  2. now go the folder prefix1 in the folder section of your project.

  3. right click on it --> build path --> use as source folder.

  4. done. the package folder wont show any error now. if it still shows, just restart the project.


suppose your project has a package like package name1.name2.name3.name4 (declared package)

your package explorer shows
package top level named name1.name2
sub packages named name3.name4

you will have errors because eclipse extracts the package name from the file directory structure on disk starting at the point you import from.

my case was a bit more involved, perhaps because i was using a symbolic link to a folder outside my workspace.

i first tried build build path.source source button.browse to the folder before name1 in your package.folder-name as you like (i think). but had issues.

then i removed the folder from the build path and tried file > import... > general > file system > click next > from directory > browse... to folder above name1 > click advanced button > check create links in workspace > click finish button.


i get this problem in eclipse sometimes when importing an android project that does not have a .classpath file. the one that eclipse creates is not exactly the same one that android expects. but, the android .classpath files are usually all relative, so i just copy a correct .classpath file from another project over the incorrect .classpath. i've created a video that shows how i do this:


go to src folder of the project and copy all the code from it to some temporary location and build the project. and now copy the actual code from temporary location to project src. and run the build again. problem will be resolved.

note: this is specific to eclipse.


i happened to have the same problem just now. however, the first few answers don't work for me.i propose a solution:change the .classpath file.for example,you can define the classpathentry node's path like this: path="src/prefix1/java" or path="src/prefix1/resources". hope it can help.


for me the issue was that i was converting an existing project to maven, created the folder structures according to the documentation and it was showing the 'main' folder as part of the package. i followed the instructions similar to jon skeet / jwoodchuck and went into the java build path, removed all broken build paths, and then added my build path to be 'src/main/java' and 'src/test/java', as well as the resources folders for each, and it resolved the issue.


the build path should contain the path 'till before' that of the package name.

for eg, if the folder structure is: src/main/java/com/example/dao if the class containing the import statement'package com.example.dao' complains of the incorrect package error, then, the build path should include:src/main/java this should solve the issue.


happens for me after failed builds run outside of the ide. if cleaning your workspace doesn't work, try: 1) delete all projects 2) close and restart sts/eclipse, 3) re-import the projects


if you have imported an existing project, then just remove your source folders and then add them again to build path, and restart eclipse. most of the times eclipse will keep showing the error till you restart.


the only thing that worked for me is deleting the project and then importing it again. works like a charm :)


move your problem *.java files to other folder.

click 'src' item and press "f5".

red crosses will dissaperar.

return your *.java files to "package path", click 'src' item and press "f5".

all should be ok.


i just ran into this problem, and since mr. skeet's solution did not work for me, i'll share how i solved this problem.

it turns out that i opened the java file under the 'src' before declaring it a source directory.

after right clicking on the 'src' directory in eclipse, selecting 'build path', and then 'use as source folder'

close and reopen the already opened java file (f5 refreshing it did not work).

provided the path to the java file from "prefix1" onwards lines up with the package in the file (example from the requester's question prefix1.prefix.packagename2). this should work

eclipse should no longer complain about 'src.'

Related Query

More Query from same tag