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中文網其他相關文章!