声明的包测试与预期的包不匹配

编程入门 行业动态 更新时间:2024-10-09 10:22:45
本文介绍了声明的包测试与预期的包不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以,我有以下代码:

package test; import test.Pi; public class Demo { public static int pi = 3; public static void main (String args[]) { System.out.println("Hello!"); Pi.main(args); System.out.println("Hello again!"); } }

但是eclipse总是在第一行抛出一个错误,说声明的包测试与预期的包不匹配". 任何帮助赞赏!谢谢!

But eclipse keeps throwing up an error at the very first line, saying "The declared package test does not match the expected package". Any help apreciated! Thanks!

推荐答案

这与 import 无关-这意味着您要尝试声明该软件包此类(Demo)是test,但是编译器错误表明您将其放置在错误的位置-您将其放置在源路径的根目录中,而不是在名为test的目录中在源根目录下.

That's not a matter of importing - that means you're trying to declare that the package for this class (Demo) is test, but the compiler error shows that you've got it in the wrong place - you've got it in the root of your source path, instead of in a directory called test under the source root.

三个可能的更改:

  • 不要将其放在test包中;给定您的问题的标题,还不清楚您是否尝试这样做.您不需要导入与要声明的类在同一包中的任何类.

  • Don't put it in the test package; given the title of your question, it's not clear whether you were trying to do that or not. You don't need to import any classes which are in the same package as the class you're declaring.

将Demo.java移到test文件夹中.

如果test文件夹中已经存在Demo.java ,请更改构建配置,使其 parent 目录为源根目录.

If Demo.java is already in a test folder, change your build configuration so that its parent directory is the source root.

更多推荐

声明的包测试与预期的包不匹配

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

发布评论

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

>www.elefans.com

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