Eclipse: The declared package does not match the expected package
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".
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.'
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.