2015-11-07 46 views
0

我試圖將多個參數傳遞給一個java程序。 Apache Commons CLI界面已正確設置並可正常工作。然而,當我嘗試使用Java Apache Commons CLI找不到setArgs()

setArgs(Option.UNLIMITED_VALUES),它給了我一個錯誤

The method setArgs(int) is undefined for the type Options.

我的代碼如下所示:

import java.io.Console; 
import java.util.Arrays; 
import java.io.IOException; 
import org.apache.commons.cli.*; 


public class main { 

public static void main(String[] args) { 

    @SuppressWarnings("deprecation") 
    CommandLineParser parser = new BasicParser(); 

    Options options = new Options(); 
    options.setArgs(Option.UNLIMITED_VALUES); 
    options.addOption("p", true, "Program under test"); 
    options.addOption("o", true, "Oracle"); 
    options.addOption("n", true, "Number of test cases"); 

    try { 
     CommandLine commandline = parser.parse(options, args); 

     System.out.println(commandline.getOptionValue("p")); 

    } catch (ParseException e) { 
     System.out.println("Command line failed."); 
     e.printStackTrace(); 
    } 

} 

} 

回答

1

setArgs是與OptionOptions

的方法
+0

工作!謝謝! –

+0

但是,這會產生另一個問題。現在同一行給了我「不能從類型選項」中對非靜態方法setArgs(int)進行靜態引用。任何線索? –

+0

你可能靜態地調用了'Option.setArgs'。在嘗試在該類的實例上使用setArgs之前,創建一個'Option'的實例 – Reimeus

相關問題