首页 > 解决方案 > import static: 'MainController' 不是可以解析的符号

问题描述

我有一个要从中导入公共静态方法 (getModPart()) 的类。getModePart() 的来源是 MainController。以下是 MainController 中的相关定义:

主控制器

public class MainController implements Initializable
{

// ...

// Variable declared globally:

private static Part currentModPart;

// Functions that use the above variable:

public static Part getModPart() 
{
   return currentModPart;
}

public static void setModifiedPart(Part modifyPart) 
{
   MainController.currentModPart = modifyPart;
}

然后我试图将 MainController.getModPart 导入到的类具有以下内容:

修改PartController

// various import statements, including the one below. In the import statement below, IntelliJ highlights 
// only the MainController text below in red, and hovering the cursor over it reveals a message, 
// "Cannot resolve symbol MainController"'

import static View_Controller.MainController.getModPart;


// Below is the code that involves the getModPart() function that I want to use from MainController

private Part modifiedPart;
    
public ModifyPartController()
{
   modifiedPart = getModPart();
}

所以我不明白为什么 MainController 不能导入。我应该寻找什么来排除一些可能的原因?

标签: javaintellij-ideajavafx

解决方案


我的论点是 Jetbrains IDE 无法找到 Controller 的实际类型定义,因为 Stimulus 只是从“@stimulus/core”导出 *,并且 IDE 无法按照间接方式在@stimulus/核心库。

显然对于 IntelliSense 来说并不完美,但你的捆绑器仍然应该可以很好地编译它


推荐阅读