[英]Issue with java.lang.NumberFormatException
我有一個變量,其中包含一些影響創建的weka模型的參數。 我想自動更改參數值。 我有以下幾點:
String c [] ={"1.0", "10.0", "20.0", "30.0", "40.0", "50.0", "60.0","70.0", "80.0",
"90.0","100.0", "200.0", "300.0", "400.0","500.0", "600.0", "700.0", "800.0", "1000.0",
"2000.0"};
System.out.println(c[1]);
String opt = ("-C "+c[0] +"-L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K
weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0 ");
String [] options = opt.split(" ");
obj.train(new File(obj.str.get(2)), options);
我想在循環內自動更改C參數。 但是,當我寫下面的內容時:
String opt = ("-C "+c[1] +"-L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0 ");
我收到一個java.lang.NumberFormatException
:輸入字符串。 我可能需要做些什么才能正常工作? 錯誤在上面的代碼的最后一行。
我試一試:
String c [] ={"1.0", "10.0", "20.0", "30.0", "40.0", "50.0", "60.0","70.0", "80.0", "90.0","100.0", "200.0", "300.0", "400.0","500.0", "600.0", "700.0", "800.0", "1000.0", "2000.0"};
for (i = 0; i < c.length; i++){
String opt = String.format("-C %S 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0 ",c[i]);
}
我使用String.format(“”,...)函數並添加%S作為占位符,其中c [i]的值將被放入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.