簡體   English   中英

據我所知,showinputdialog 返回一個字符串類型的 output 但它給了我一個錯誤,它無法將 object 轉換為字符串

[英]As far as I know showinputdialog returns an output of type string but it gives me an error that it cannot convert the object to a String

 String val = JOptionPane.showInputDialog(null,
            "Search item to Edit ",
            "Warning",
            JOptionPane.QUESTION_MESSAGE,
            null,
            new String[]{"Item name", "Item no.","Price"},
            "");

錯誤:

不兼容的類型:Object 無法轉換為字符串

有了這么多參數, showInputDialog方法不返回字符串,而是返回 Object,如javadoc中所述

正如Swing 教程中所建議的,您只需將結果轉換為字符串。

String val = (String) JOptionPane.showInputDialog(null,
        "Search item to Edit ",
        "Warning",
        JOptionPane.QUESTION_MESSAGE,
        null,
        new String[]{"Item name", "Item no.","Price"},
        "");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM