Eclipse expects the declared package to match the directory hierarchy - so it's expecting your Java file to be in a directory called "Devices" under your source root. At the moment it looks like the file is directly in your source root. So create the appropriate directory, and move the file in there.
Note that conventionally, packages are in lower case and include your organization name in reverse DNS order, e.g.
Make sure that You have created a correct package.You might get a chance to create folder instead of package
Create directory [your.project.name] in workspace root directory of your project.
Copy *.java from "src" to that directory.
Close and reopen project.
This happened to me when I was checking out a project from an svn repository in eclipse. There were jar files in my .m2 folder that eclipse wasn't looking at. To fix the issue I did:
right click project folder Configure > Convert to Maven Project
and that solved the issue.
There are a million answers, but here's another one: copy the files into a new package, delete the old package and rename the new package to the old package's name.
Make sure you are not using default package. Create a new package with name 'devices' and copy this code inside it and use.
I had have this sort situations when I copied classes from other packages/projects.
Menu->Project->Clean usually helps.
In my case I selected the error marker in the Problems tab and deleted it since the Java's file main method was being executed correctly. That is some glitch in Eclipse Neon with the multitude of plugins it has installed.
I faced this issue too when I had imported an existing project to eclipse. It was a gradle project, but while importing I imported it as regular project by clicking General-> Existing Projects into Workspace. To resolve the issue I've added Gradle nature to the project by :::: Right click on Project folder -> Configure-> Add Gradle Nature
I was using Spring Tool Suite 4. Not able to figure out the issue. The directory structure was according to the package name.
But cleaning the project helped me.
I had the same issue with a maven project in Eclipse IDE. I was able to resolve it by replacing the .classpath file with the correct format. After replacing close and open the project.
Sample .classpath file
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" output="target/classes" path="src/main/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/webapp"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="src" output="target/test-classes" path="src/test/java"> <attributes> <attribute name="optional" value="true"/> <attribute name="maven.pomderived" value="true"/> <attribute name="test" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <attributes> <attribute name="maven.pomderived" value="true"/> </attributes> </classpathentry> <classpathentry kind="output" path="target/classes"/> </classpath>
you might want to check your Java 'build path' in the project properties, if the 'source' directory (path) is not properly setup in there, then this will cause this error to occur for all the classes therein.
So the path must specify the 'root' (containing) directory in which the sources within the package exists ...
Make sure that
Devices is defined as a source folder in the project properties.
Got the same kind of error but my package was absolutely correct. When I just closed and opened my editor, the error disappears. Hope this might help in some scenarios.
I fixed this by removing an "excluding" attribute for that package in my
.classpath file. Remove the attribute, not the whole tag, or "src/java" will cease to be a source folder.
<classpathentry excluding="com/myproject/mypackage/mysubpackage/" kind="src" path="src/java"/>
Create a new package under your project called "Devices" and place your class in it. This is equivalent to the class being placed in a directory called "Devices" in your project source folder.
You need to have the class inside a folder
This problem got resolved by mentioning the package name
I moved my file Test_Steps.java which was under package stepDefinition
by just adding the package stepDefinition the problem got resolved
So this problem can occur when you have a package and you are not using in your class file.
Adding it has resolved the problem and the error was no longer appearing.
I fix it just changing the name to lowercase and now Eclipse recognizes the package.
I had this problem - the other classes within my package were fine, but one class had the error against it. There was nothing wrong with the package declaration.
I fixed it by doing
refactor->move and moved the class to another package temporarily, then
refactor->move back to the original package.
I resolved the problem by following these steps:
Select the project - Right click - java build path.
In source tab - you change the
Eclipse will reorder all the project.
Solution 1 : One solution that worked for me when this error "The declared package does not match the expected package" occured for a project I checked-out from eclipse CVS :
1.Right click the project in the navigation bar and click 'delete'
2.Make sure 'Delete project contents on disk' option is NOT checked, and click OK.
3.Now after the project is deleted, go to File -> Import -> General -> Existing Projects into Workspace
4.Select your workspace from the directory listing and check the box next to your project name. Click 'Finish'
Solution 2 : Once again I got this error with the following message
Eclipse build errors - java.lang.Object cannot be resolved I had to follow another route mention here and the error went away.
In the mean time, the work around is to remove the JRE System Library from the project and then add it back again. Here are the steps:
- Go to properties of project with the build error (right click > Properties) View the "Libraries" tab in the "Build Path" section Find the "JRE System Library" in the list (if this is missing then this error message is not an eclipse bug but a mis-configured project)
- Remove the "JRE System Library"
- Hit "Add Library ...", Select "JRE System Library" and add the appropriate JRE for the project (eg. 'Workspace default JRE')
- Hit "Finish" in the library selection and "OK" in the project properties and then wait for the re-build of the project
Hopefully the error will be resolved ...
Try closing and re-opening the file.
It is possible to get this error in eclipse when there is absolutely nothing wrong with the file location or package declaration. Try that before spending a lot of time trying these other solutions. Sometimes eclipse just gets confused. It's worked for me on a number of occasions. I credit the idea to Joshua Goldberg.
- 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
- Java - Eclipse - The declared package "edu.uci.ics.crawler4j.examples.basic" does not match the 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)
- handling main and test without "The declared package com.pkgY does not match the expected package dirX.src.main.java.com.pkgY" in Eclipse
- How do I fix a "declared package does not match the expected package" error on Eclipse?
- Eclipse declared package does not match expected package
- build path - the declared path does not meet the expected package
- Eclipse says package declaration does not match expected package ""
- 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
- Ant javac: package x does not exist, but i added the x.jar to the java build path libraries
- The action value does not match a navigation case outcome
- Statet in eclipse does not find the rj package
- The compile time user.agent value does not match the runtime user.agent value
- Eclipse: My SSH key does not match the SSH key associated with my Heroku Acct
- Bean property 'empname' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
- JAX-RS sub resource @PathParam value does not match any @Path annotation template parameters of the java method and its enclosing java type
- Eclipse Build Path - declared packages does not match
- How do I autofix "The declared package does not match..." errors in Eclipse?
- package sun.net.www.protocol.https is declared in module java.base, which does not export it
- Eclipse linked folder error "does not match the expected package"
- selenium declared package doesn't match expected package
- Invalid key hash! the key hash does not match any stored key hashes facebook android
More Query from same tag
- JAX-RS Rest services stopped deploying on Eclipse Glassfish
- Tomcat can't find JDBC driver under Eclipse?
- how to stop writing the android logcat into file in dos prompt
- Tokens start with double quotes followed by some tokens and end with double quotes, into one token
- Confusion over execution order
- subversion issue with eclipse
- Eclipse deploys content of WebContent folder to WEB-INF folder.
- Changing QMAKESPEC from within eclipse?
- Capturing http with Fiddler using Jsoup (through Eclipse)
- eclipse can not format the html file
- Eclipse don't save editor annotations settings
- Stop Eclipse from mangling my comments
- Browse Nginx Source Code in Eclipse CDT
- Subclipse - Checkout lacking root directory
- How do I connect to Hive on EMR through Eclipse?
- Importing External JAR to Websphere Liberty? [NoClassDefFoundError]
- EAR maven plugin does not see project dependency
- File that I recorded with MediaRecorder can't be played
- Eclipse doesn't seem to want to compile a new version of my class. I'm getting the same error even after (I think) fixing it
- Problem with horizontal grey/gray bar when editing files in Eclipse 2019-09+
- ASM files in Eclipse
- Browser forces me to download my index.jsp page instead of viewing it. I'm using github pages to host my project
- Find class usages
- Getting image path to use it as system tray icon
- Displaying camel cased words as such with underscores in Eclipse
- Run a class in a sub package in a jar file on Windows command line
- RavenDB query alias in Java
- How to make an Eclipse plug-in to run standalone application
- Difference between DSL, DSLR, DRL in drools
- Eclipse not detecting Sony Ericsson Xperia for debugging?