包名与文件路径不对应 - IntelliJ [英] Package name does not correspond to the file path - IntelliJ

查看:289
本文介绍了包名与文件路径不对应 - IntelliJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 VCS 导入一个项目(嗯,我实际上是第一次这样做),这是我(导入的)项目的结构:

I'm trying to import a project from VCS (well, I'm doing it for the first time actually) and this is my (imported) project's structure:

顺便说一句.此屏幕是在多次尝试更改这些目录的属性(在其上下文菜单中)后生成的.

BTW. this screen is made after many tries of changing these directories' properties (in their context menus).

在这些源文件中出现以下错误:

In these source files' I have a following error:

有一次它对 badugi.client 没有任何反应,但它只在 badugi.server 中报告此错误.我完全不知道它是如何工作的......

One time it had nothing against badugi.client but it reported this error only in badugi.server. I have completely no idea how it works...

同样目录中的类也看不到彼此.

Also classes in the same directories do not see each other.

这是来自 ClientWorker 类的代码,它与 Server 位于同一目录中(如您在第一张图片中看到的),因此它应该知道 服务器是.

This is a code from ClientWorker class which is located (as you can see in the first image) in the same directory as Server so it should know what Server is.

我很确定这段代码在我朋友的 IDE 中运行良好.如何配置 IntelliJ 以使其工作?

I'm pretty sure this code worked well in my friend's IDE. How do I configure IntelliJ to make it work?

推荐答案

从目录结构来看,有client和server两个包,但是代码需要badugi.client和badugi.server包.

Judging from the directory structure, you have two packages client and server, but the code expects packages badugi.client and badugi.server.

这里有一个解决方法:

  1. 将光标置于带下划线的包语句 (package badugi.server)
  2. 点击 ALT + ENTER
  3. 选择选项移动到包badugi.server.这将自动修复您的目录结构以匹配声明的包
  1. Position your cursor to the underlined package statement (package badugi.server)
  2. Hit ALT + ENTER
  3. Select option Move to package badugi.server. This will automatically fix your directory structure to match the declared package

  1. 在项目资源管理器中右键单击 src
  2. 选择New/Package并创建包badugi
  3. 选择客户端和服务器包并将它们拖到 badugi 包中

这篇关于包名与文件路径不对应 - IntelliJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆