0

I am trying to get multiple arguments passed to a java program. The Apache Commons CLI interface has been set up correctly and works. However, when I try to use

setArgs(Option.UNLIMITED_VALUES), it gives me an error

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

My code looks like this:

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 Answer 1

1

setArgs is a method related to Option not Options

Sign up to request clarification or add additional context in comments.

3 Comments

However, this creates another issue. Now the same line gives me "Cannot make a static reference to the non-static method setArgs(int) from the type Option". Any clue?
You're probably calling Option.setArgs statically. Create an instance of Option before attempting to use setArgs on the instance of that class
You're a lifesaver! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.