score:63
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.
com.foo.devices;
score:0
make sure that you have created a correct package.you might get a chance to create folder instead of package
score:0
create directory [your.project.name] in workspace root directory of your project.
copy *.java from "src" to that directory.
close and reopen project.
score:0
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.
score:0
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.
score:0
make sure you are not using default package. create a new package with name 'devices' and copy this code inside it and use.
score:0
i had have this sort situations when i copied classes from other packages/projects.
menu->project->clean usually helps.
score:0
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.
score:0
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
score:0
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.
score:0
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>
score:0
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 ...
score:1
make sure that devices
is defined as a source folder in the project properties.
score:1
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.
score:1
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"/>
score:2
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.
score:2
you need to have the class inside a folder devices
.
score:2
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.
score:3
i fix it just changing the name to lowercase and now eclipse recognizes the package.
score:11
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.
score:16
i resolved the problem by following these steps:
select the project - right click - java build path.
in source tab - you change the
src
tosrc/main/java
.eclipse will reorder all the project.
score:49
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 ...
score:150
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.
Source: stackoverflow.com
Related Query
- 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
- Error Message on my first App calculating 2 values learned from Youtube video
- Tabs in Action Bar Sherlock
- Any way to hide test classes from the Hierarchy View in Eclipse?
- java.lang.ClassCastException when casting Object-result of java.lang.reflect.Method.invoke
- Include HTML File in Eclipse Dynamic Web Project
- Eclipse strings auto closing
- How to utilize data stored in a multidimensional array
- Shortcut for importing multiple jars in eclipse?
- How to add border to button?
- Eclipse Luna (4.4.0) and Subclipse not working
- Deploying a Play Framework application on port 80 beside Apache
- Eclipse 3.8 with Ubuntu 13.10
- Ctrl+click doesn't work in Eclipse Juno
- Truestudio atollic (an IDE based on eclipse) creates empty binary file despite of not empty elf file and a lot of code
- how to include Android gradle dependencies in Eclipse
- Multiple Git repositories for each Eclipse project or one Git repository
- Deletion of directory in Java
- What are some SWT datagrids/tables?
- Unfortunately,"App" has stopped, OnClickListener
- Can't install my application to my plugged in device
- Compiling in Eclipse with gcc's -lpthread and -lrt set
- Multi module maven import issue in RAD 8.5
- Loading array from a text file in assets folder (Android)
- How to switch JProfiler launcher in Eclipse integration
- Final in method parameter in eclipse
- Text File Number Holder isn't working, how do I fix it?
- rror configuring application listener of class org.springframework.web.context.ContextLoaderListener
- What exactly does "An internal error occurred during: "ProjectName". null argument:" mean? Eclipse
- Eclipse plugin to SonarQube 4.0 not finding provisioned project or creating new project
- .click syntax issue, Selenium, JAVA, Eclipse, Junit, EDGE browser