Error calling .parse() #120

Closed
Raos123 opened this Issue Jun 20, 2012 · 2 comments

Comments

Projects
None yet
2 participants

Raos123 commented Jun 20, 2012

I am getting a Parse Error when i first initialize my JCommander object with just its object and then call parse on the string i wish to parse. Here is my stack:
Exception in thread "main" com.beust.jcommander.ParameterException: Only one @parameter with no names attribute is allowed, found:private java.util.List JCommandLine.claim and private java.util.List JCommandLine.claim
at com.beust.jcommander.JCommander.addDescription(JCommander.java:402)
at com.beust.jcommander.JCommander.createDescriptions(JCommander.java:385)
at com.beust.jcommander.JCommander.parse(JCommander.java:186)
at Main.main(Main.java:16)

My code is :

import java.io.File;
import java.util.Scanner;

import com.beust.jcommander.JCommander;

public class Main {

public static void main(String[] args) {
JCommandLine commandline = new JCommandLine();
JCommander command = new JCommander(commandline);
command.setProgramName("ClaimServerPost");
command.usage();
System.out.println("\nEnter options:");
Scanner in = new Scanner(System.in);
command.parse(in.nextLine());
}

}

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.converters.FileConverter;

public class JCommandLine {

@Parameter(names={"-f","--fax"},description="physician fax number")
private String faxNumber = "";

@Parameter(names={"-u","--username"},description="username with which to authenticate", required=true)
private String username;

@Parameter(names={"-p","--password"},description="password with which to authenticate", required=true)
private String password;

@Parameter(names={"-v","--verbose"},description="show verbose output")
private Boolean verbose;

@Parameter(names={"-s","--service"},description="URL of the service which to POST")
private String service_url = "https://claims.covermymeds.com/cmmimport/";

@Parameter(names={"-x","--suppress-browser"},description="suppress opening a browser window for each URL")
private Boolean suppress;

@Parameter(names={"-c","--claim"},description="File where claim is present", converter=FileConverter.class)
private File claimFile;

@Parameter(description = "The claim itself if --claim, -c is not supplied surrounded in \"\"s")
private List<String> claim = new ArrayList<String>();

public File getClaimInFile() {
    return claimFile;
}

public List<String> getClaim() {
    return claim;
}

public String getFaxNumber() {
    return faxNumber;
}

public String getUsername() {
    return username;
}

public String getPassword() {
    return password;
}

public Boolean getVerbose() {
    return verbose;
}

public String getService_url() {
    return service_url;
}

public Boolean getSuppress() {
    return suppress;
}

}

Owner

cbeust commented Jun 26, 2012

How do I reproduce this issue? I don't know what you typed. If I just type "return", I get:

Exception in thread "main" com.beust.jcommander.ParameterException: The following options are required: -u, --username -p, --password 

which looks correct.

Raos123 commented Jun 26, 2012

disregard this issue. Sorry, i found out today that i in fact have an older version of JCommander.

@cbeust cbeust closed this Jun 26, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment