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中文网其他相关文章!