尽管添加了库,IntelliJ 仍无法解析符号

时间:2021-04-08 22:17:16

标签: java intellij-idea

我正在创建一个外部库来在我的客户端/服务器程序之间共享代码。 IntelliJ 似乎无法导入这个 jar 文件,我不明白为什么,我遵循了我在网上找到的所有建议。

我将 jar 添加到我的 import json import requests import itertools def get_player_data() -> list: response = requests.get("https://mach-eight.uc.r.appspot.com/") return json.loads(response.text)["values"] def build_height_index(player_data: list) -> dict: height_index = {} for player in player_data: name = f"{player['first_name']} {player['last_name']}" h = int(player["h_in"]) height_index.setdefault(h, []).append(name) return height_index def search(player_data: list, n: int) -> list: height_index = build_height_index(player_data) pairs = [] for h in height_index: # avoid double counting pairs if h > n / 2: continue player_list = height_index.get(h, []) if h == n / 2: # the players in this list are pairs with each other new_pairs = [*itertools.combinations(player_list, r=2)] else: # find the list of players with the matching height matching_height = n - h matching_list = height_index.get(matching_height, []) new_pairs = [*itertools.product(player_list, matching_list)] pairs += new_pairs return pairs def format_output_pairs(pairs: list) -> list: """ This will format the output in a string like you had it, but otherwise it's unnecessary. """ return [" & ".join(sorted(x)) for x in pairs] def find_pairs(n: int) -> list: player_data = get_player_data() pairs = search(player_data, n) return format_output_pairs(pairs) ### Example output: # > find_pairs(140) # ['Brevin Knight & Mike Wilks', # 'Chucky Atkins & Nate Robinson', # 'Nate Robinson & Speedy Claxton'] 文件夹中,并将其作为库添加到我的主模块中(称为“common”: modules setting screen

这是错误(使用 libUser 在我的每个实例上重复)。在导入语句中,它说“通用包不存在”: cannot find symbol error

我试过使缓存失效,但似乎也没有用。我在一个新项目上尝试了同样的导入,只是为了看看我是否做错了什么,它在那个新项目上运行得很好,所以我不确定这里出了什么问题。

编辑: 我注意到此错误仅发生在 Packet 文件夹中的包中的文件中。所以基本上,src 可以找到 jar,因为它只在 src 文件夹中,但 Main 不能,因为它在 RegistrationController 中。

1 个答案:

答案 0 :(得分:0)

问题是我制作的共享代码不在包中,只是一个 src 文件夹。因此,我的默认包 (src) 中的代码可以访问类,但不能访问包中的代码。为了解决这个问题,我将共享类放在一个包 (com) 中,将它们导出为 jar,然后将其导入到我的项目中。现在,我的包可以执行 com.Packetcom.User 并成功获取文件。