搜尋
首頁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脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。