score:108
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".
score:-1
- right click on the external folder which is having package
src.prefix1.prefix.packagename1 src.prefix1.prefix.packagename2
click build path --> remove from build path.
now go the folder prefix1 in the folder section of your project.
right click on it --> build path --> use as source folder.
done. the package folder wont show any error now. if it still shows, just restart the project.
score:0
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 path.java build path.source tab.link 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.
score:0
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: https://www.youtube.com/watch?v=ivihgeahs1ynto
score:0
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.
score:0
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.
score:0
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.
score:0
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.
score:1
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
score:2
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.
score:2
the only thing that worked for me is deleting the project and then importing it again. works like a charm :)
score:11
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.
score:71
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.'
Source: stackoverflow.com
Related Query
- Java - Eclipse - The declared package "edu.uci.ics.crawler4j.examples.basic" does not match the expected package ""
- handling main and test without "The declared package com.pkgY does not match the expected package dirX.src.main.java.com.pkgY" in Eclipse
- The declared package does not match the expected package ""
- Eclipse: The declared package does not match the expected package
- Eclipse: "declared package does not match the expected package", but buildpath does define the declared package
- the declared package does not match the expected package
- The declared package does not match the expected package for apache-commons
- Eclipse declared package does not match expected package
- The declared package "facts" does not match the expected package ""
- libgdx: The declared package does not match the expected package ""
- The declared package does not match the expected package. (android.support.v7.appcompat)
- How do I fix a "declared package does not match the expected package" error on Eclipse?
- Eclipse says package declaration does not match expected package ""
- build path - the declared path does not meet the expected package
- Statet in eclipse does not find the rj package
- Eclipse Build Path - declared packages does not match
- Eclipse linked folder error "does not match the expected package"
- Java eclipse does not recognize the import org.apache.poi package that is already imported with maven
- The version of GCC does not match the expected version
- JFace signer information does not match signer information of other classes in the same package
- Java compiler level does not match the version of the installed Java project facet
- Eclipse does not start when I run the exe?
- How to avoid Eclipse importing a class when putting the class name in the comments, so that checkstyle does not complain later?
- Eclipse does not refresh project files in package explorer view
- "The project: swing which is referenced by the classpath, does not exist" in Eclipse when project name is the same as workspace name
- Why when I rename a project in Eclipse does Tomcat not pick up the new resource name?
- Eclipse does not return to the beginning of the file in Find/Replace
- Any way of working with Eclipse WTP that does not mean redeploying the _WHOLE_ application when a JSP page is changed
- Why does the display in Eclipse not support recursive functions in Java?
- Eclipse says jre does not support the current compiler level of 1.8 but it is set at 1.7
More Query from same tag
- Using flock() to lock a file opened with fopen()
- Mixed Modular and Non-Modular Development in Eclipse using Java 11
- How to execute an eclipse app in console mode
- What would cause my source files to be greyed out with a strikethrough through the file icon?
- why are my eclipse code error labels lagging
- changing background color on every clock tick
- Renaming application
- Cordova development with JBoss Palette issue
- How to debug a swing UI?
- how to register external glassfish 3.1.2.2 on eclipse indigo 3.7.2 on mac 10.7.5
- Is there a ctrl-click through to resource bundles in Eclipse?
- syntax error on token "-", -- expected
- Eclipse IDE Redo and Inspect key command Conflicts
- Can't use JFace and SWT in eclipse without creating plugin
- CDT An internal error occurred during: "Setting up indexer"
- How to add checkbox image in eclipse e4?
- eclipse dies every few minutes with latest jdk saying 'out of space in CodeCache for adapters'
- Fold highlighted text in eclipse
- How to get all most common eclipse sources?
- How to make a custom Eclipse run launcher that launches a particular Class?
- Application is crashing with null pointer exception if i pass null value to method
- Eclipse - referencing Java resources
- How to get all current running LaunchConfigurations (run- and debugmode) programmatically?
- Eclipse OSGi bundle reqiure another bundle's fragment
- Can't import Apache HTTP in Eclipse
- Speeding up Android app building - Java compiler to use multiple CPU cores
- Scroll in eclipse quick search preview
- Error running C app in eclipse
- Project is missing required library
- Error Exporting Vuforia Unity Project into Eclipse