The declared package does not match the expected package Eclipse


⚠️ The declared package "com.example.package" does not match the expected package "com.xyz.package"

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

	at com.code2care.java.tutorials.MyClass.main(MyClass.java:5)

When you create an Android Application you define the package name (as java reverse domain name conventions: com.example.myapp) and your project folder (directory) must have that package name, so should be the package statements for java files what reside inside this folder.

If there is a mismatch you would get this error message.

This is not an Android Programming specific error but a Compilation error when the location of the Class has changed. If you are using IDE such as Eclipse, simply hover over the package and Select either of the two options available - "two quick fixes available"

  1. Move to package "com.xyz.package": This will move your class to the new package - if the package does not exists, eclipse will create it for you.
  2. Change package to "com.example.package": This will rename the package import statement to the current location.
Java Class Error - The declared package does not match the expected package Eclipse
Java Class Error - The declared package does not match the expected package Eclipse





Recent Posts:
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.