英文:
Picocli - java.lang.NumberFormatException
问题
@Parameters(index = "0")
private Double min_c_re;
@Parameters(index = "1")
private Double min_c_im;
@Parameters(index = "2")
private Double max_c_re;
@Parameters(index = "3")
private Double max_c_im;
@Parameters(index = "4")
private Integer max_n;
@Parameters(index = "5")
private Integer width;
@Parameters(index = "6")
private Integer height;
@Parameters(index = "7")
private Integer divisions;
@Parameters(index = "8", arity = "1..*")
private List<URL> hosts;
@Override
public void run() {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
List<SubDivider.SubDivision> subDividedImages = new SubDivider(divisions, divisions).divide(image);
ExecutorService threadPool = Executors.newCachedThreadPool();
double realRange = max_c_re - min_c_re;
double imaginaryRange = max_c_im - min_c_im;
for (int i = 0; i < subDividedImages.size(); i++) {
SubDivider.SubDivision subDivision = subDividedImages.get(i);
BufferedImage subDividedImage = subDivision.getImage();
URL host = hosts.get(i % hosts.size());
double xPercent = subDivision.getOriginalMinX() / (double) width;
double yPercent = subDivision.getOriginalMinY() / (double) height;
double widthPercent = subDividedImage.getWidth() / (double) width;
double heightPercent = subDividedImage.getHeight() / (double) height;
String resource = new StringJoiner("/")
.add("/mandelbrot")
.add(Double.toString(min_c_re + realRange * xPercent))
.add(Double.toString(min_c_im + imaginaryRange * yPercent))
.add(Double.toString(min_c_re + realRange * xPercent + realRange * widthPercent))
.add(Double.toString(min_c_im + imaginaryRange * yPercent + imaginaryRange * heightPercent))
.add(Integer.toString(subDividedImage.getWidth()))
.add(Integer.toString(subDividedImage.getHeight()))
.add(Integer.toString(max_n))
.toString();
URL url;
try {
url = new URL(host, resource);
} catch (MalformedURLException exception) {
System.err.println("Exception: " +
exception.getMessage());
return;
}
threadPool.submit(new SubDivisionGenerator(url, subDividedImage));
}
try {
threadPool.shutdown();
threadPool.awaitTermination(1, TimeUnit.HOURS);
} catch (InterruptedException exception) {
System.err.println("Exception: "
+ exception.getMessage());
return;
}
File file = new File("output.pgm");
HashMap<String, Object> params = new HashMap<>();
try {
Imaging.writeImage(image, file, ImageFormats.PGM, params);
} catch (ImageWriteException | IOException exception) {
System.err.println("Exception: "
+ exception.getMessage());
return;
}
}
当我运行命令 java -jar target/cli-1.0.0.jar -1 -1.5 2 1.5 1024 10000 10000 4 http://localhost:8080
时,我得到以下异常:
Could not convert 'https://localhost:8080' to Integer for positional parameter at index 6 (<height>): java.lang.NumberFormatException: For input string: "https://localhost:8080"
使用的 picocli 版本为 2.3.0。
英文:
@Parameters(index = "0")
private Double min_c_re;
@Parameters(index = "1")
private Double min_c_im;
@Parameters(index = "2")
private Double max_c_re;
@Parameters(index = "3")
private Double max_c_im;
@Parameters(index = "4")
private Integer max_n;
@Parameters(index = "5")
private Integer width;
@Parameters(index = "6")
private Integer height;
@Parameters(index = "7")
private Integer divisions;
@Parameters(index = "8", arity = "1..*")
private List<URL> hosts;
@Override
public void run() {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
List<SubDivider.SubDivision> subDividedImages = new SubDivider(divisions, divisions).divide(image);
ExecutorService threadPool = Executors.newCachedThreadPool();
double realRange = max_c_re - min_c_re;
double imaginaryRange = max_c_im - min_c_im;
for (int i = 0; i < subDividedImages.size(); i++) {
SubDivider.SubDivision subDivision = subDividedImages.get(i);
BufferedImage subDividedImage = subDivision.getImage();
URL host = hosts.get(i % hosts.size());
double xPercent = subDivision.getOriginalMinX() / (double) width;
double yPercent = subDivision.getOriginalMinY() / (double) height;
double widthPercent = subDividedImage.getWidth() / (double) width;
double heightPercent = subDividedImage.getHeight() / (double) height;
String resource = new StringJoiner("/")
.add("/mandelbrot")
.add(Double.toString(min_c_re + realRange * xPercent))
.add(Double.toString(min_c_im + imaginaryRange * yPercent))
.add(Double.toString(min_c_re + realRange * xPercent + realRange * widthPercent))
.add(Double.toString(min_c_im + imaginaryRange * yPercent + imaginaryRange * heightPercent))
.add(Integer.toString(subDividedImage.getWidth()))
.add(Integer.toString(subDividedImage.getHeight()))
.add(Integer.toString(max_n))
.toString();
URL url;
try {
url = new URL(host, resource);
} catch (MalformedURLException exception) {
System.err.println("Exception: " +
exception.getMessage());
return;
}
threadPool.submit(new SubDivisionGenerator(url, subDividedImage));
}
try {
threadPool.shutdown();
threadPool.awaitTermination(1, TimeUnit.HOURS);
} catch (InterruptedException exception) {
System.err.println("Exception: "
+ exception.getMessage());
return;
}
File file = new File("output.pgm");
HashMap<String, Object> params = new HashMap<>();
try {
Imaging.writeImage(image, file, ImageFormats.PGM, params);
} catch (ImageWriteException | IOException exception) {
System.err.println("Exception: "
+ exception.getMessage());
return;
}
}
When I run the command java -jar target/cli-1.0.0.jar -1 -1.5 2 1.5 1024 10000 10000 4 http://localhost:8080
I get this exception:
Could not convert 'https://localhost:8080' to Integer for positional parameter at index 6 (<height>): java.lang.NumberFormatException: For input string: "https://localhost:8080"
picocli version 2.3.0 is used
答案1
得分: 5
尝试双短线 https://picocli.info/#_double_dash:
java -jar target/cli-1.0.0.jar -- -1 -1.5 2 1.5 1024 10000 10000 4 http://localhost:8080
负数不能直接传递到命令行。它们没有被识别为位置参数,因此它在说您的 URL 处于第 6 位置。
英文:
Try double dash https://picocli.info/#_double_dash:
java -jar target/cli-1.0.0.jar -- -1 -1.5 2 1.5 1024 10000 10000 4 http://localhost:8080
negative numbers can not be passed directly on the command line. They have not been recognized as positional parameters, therefore it is saying that your url is at position 6
答案2
得分: 3
负数中的破折号使它们看起来像是选项。尝试使用以下标志:
CommandLine.setUnmatchedOptionsArePositionalParams(true)
英文:
The dash in the negative numbers make them look like options. Try using the flag:
CommandLine.setUnmatchedOptionsArePositionalParams(true)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论