gpt4 book ai didi

java - Picocli - java.lang.NumberFormatException

转载 作者:行者123 更新时间:2023-12-01 14:07:53 28 4
gpt4 key购买 nike

@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

我得到了这个异常(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 2.3.0版本

最佳答案

试试双破折号 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

不能在命令行直接传递负数。它们未被识别为位置参数,因此表示您的网址位于位置 6

关于java - Picocli - java.lang.NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61056691/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com