声明的包不符合预期的包“

编程入门 行业动态 更新时间:2024-10-24 16:32:15
本文介绍了声明的包不符合预期的包“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用Eclipse,并且还没有使用Java。但是,我可以在命令行编译我的代码,并且生成必要的 .class 文件。在Eclipse中,它抱怨声明的包Devices与预期的包不匹配。这是什么意思,我该怎么解决?

示例代码:

public final class DevFrequency { public short messageID; public double frequency; public short converterID; public DevFrequency() {} public DevFrequency(short _messageID,double _frequency,short _converterID) { messageID = _messageID; frequency = _frequency; converterID = _converterID; } }

我的项目名称是 DeviceDDS 。

解决方案

Eclipse希望声明的包与目录层次结构相匹配 - 所以期待您的Java文件位于源根目录下的Devices目录下。目前看起来文件直接在源代码中。因此,创建相应的目录,并移动文件。

请注意,传统上,程序包是小写的,并且以反向DNS顺序包括您的组织名称,例如

com.foo.devices;

I am using Eclipse and have not used Java for sometime. However, I can compile my code on the command-line just fine and generate the necessary .class files. In Eclipse, it complains that The declared package "Devices" does not match the expected package "". What does this mean and how can I fix it?

Sample code:

package Devices; public final class DevFrequency { public short messageID; public double frequency; public short converterID; public DevFrequency() { } public DevFrequency(short _messageID,double _frequency,short _converterID) { messageID = _messageID; frequency = _frequency; converterID = _converterID; } }

The name of my project is DeviceDDS.

解决方案

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;

更多推荐

声明的包不符合预期的包“

本文发布于:2023-11-22 03:31:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615815.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不符合   声明

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!