搜索
首页Java无法解析方法 - Intellij

php小编鱼仔为您介绍本文主题:Java编程中常见问题解答。今天我们将讨论Intellij开发环境中常见的问题之一:无法解析方法。在Java开发过程中,遇到无法解析方法的情况可能会让人头疼,但实际上很可能只是一个小问题。接下来,我们将为您详细解析可能导致这一问题的原因,并提供解决方法,帮助您更顺利地进行编程工作。

问题内容

试图找出为什么我在第二种方法中收到“setobservationcode is neverused”错误。第二个片段显示了单元测试的使用位置。通过单元测试,它给我一个“无法解析“resourcehandler”中的方法“setobservationcode”错误。我看到一些人说他们通过使缓存无效并重新启动来解决该错误,但这对我来说并不成功。

public class ResourceHandlerTest extends TestCase {

    FhirContext ctx = null;
    IParser parser = null;

    // Other methods...

    public String getId(Resource resource) {
        if (resource.getIdElement() != null) {
            // Use IdType to extract the ID without additional details such as base URL or resource type.
            IdType idType = resource.getIdElement();
            return idType.getIdPart();
        } else {
            // Handle the case where the resource does not have an ID.
            return null; // Or throw an exception, depending on your requirements.
        }
    }

    public Observation setObservationCode(Observation observation, Coding coding) {
        if (observation.getCode() == null) {
            observation.setCode(new CodeableConcept().addCoding(coding));
        } else {
            observation.getCode().addCoding(coding);
        }
        return observation;
    }

    
public Observation setObservationCode(Observation observation, Coding coding) {
            if (observation.getCode() == null) {
                observation.setCode(new CodeableConcept().addCoding(coding));
            } else {
                observation.getCode().addCoding(coding);
            }
            return observation;
        }
    
      public Observation setObservationCode(Observation observation, String system, String code, String display) {
            System.out.println("Debug: Observation Before - " + observation);
    
            System.out.println("Debug: System - " + system);
            System.out.println("Debug: Code - " + code);
            System.out.println("Debug: Display - " + display);
    
            Coding coding = new Coding().setSystem(system).setCode(code).setDisplay(display);
    
            return setObservationCode(observation, coding);
        }

-----------------------------------------------------------------------------------------------

    public void testSetObservationCode() throws Exception {
            if (ctx == null) ctx = FhirContext.forR4();
            if (parser == null) parser = ctx.newJsonParser();
    
            String observationJsonFile = "src/resources/observation.json";
            String observationJson = "";
            try {
                observationJson = new String(Files.readAllBytes(Paths.get(observationJsonFile)));
            }
            catch (Exception e) { System.err.println("Failed to read observation.json file."); }
    
            Observation correctObservation = parser.parseResource(Observation.class, observationJson);
    
            ResourceHandler studentResourceHandler = new ResourceHandler();
    
            String expectedSystem = "http://example.com/system";
            String expectedCode = "12345";
            String expectedDisplay = "Test Code";
    
            Coding coding = new Coding().setSystem(expectedSystem).setCode(expectedCode).setDisplay(expectedDisplay);
            Observation modifiedObservation = studentResourceHandler.setObservationCode(correctObservation, coding);
    
            assertEquals(expectedSystem, modifiedObservation.getCode().getCodingFirstRep().getSystem());
            assertEquals(expectedCode, modifiedObservation.getCode().getCodingFirstRep().getCode());
            assertEquals(expectedDisplay, modifiedObservation.getCode().getCodingFirstRep().getDisplay());
    
        }

解决方法

您在测试中调用了第一个方法,但没有调用第二个方法。

测试中最后一行的第 4 行有 2 个参数,这是第一个参数。因此 intellij 检测不到第二个的使用。

Observation modifiedObservation = studentResourceHandler.setObservationCode(correctObservation, coding);

查看主代码块的结构,理想情况下您应该调用第二个定义(有 4 个参数),该定义又调用另一个定义。

以上是无法解析方法 - Intellij的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:stackoverflow。如有侵权,请联系admin@php.cn删除

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器