我是Java新手。我正在使用实现文本方面情感分析的代码。我知道代码应该工作,但不知何故,我不断收到以下错误。Java为什么跳过For语句?
----jGRASP exec: java -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,suspend=y,server=y sto2.STO2Core
----jGRASP: connected to debugger.
Exception in thread "main" java.lang.Exception: Alpha should be specified as a positive real number.
----jGRASP debugger: run in canvas ended
at sto2.STO2Core.main(STO2Core.java:114)
这里是我的主要功能,不外,我得到的错误
public static void main(String [] args) throws Exception {
int numTopics = 10;
int numIterations = 100;
int numSenti = 2;
int numThreads = 1;
String inputDir = null;
String outputDir = null;
String dicDir = null;
double alpha = -1;
double [] betas = null;
double [] gammas = null;
String [] betasStr = null;
String [] gammasStr = null;
boolean randomInit = false;
String sentiFilePrefix = "SentiWords-";
String wordListFileName = "WordList.txt";
String docListFileName = "DocumentList.txt";
String wordDocFileName = "BagOfSentences.txt";
for (int i = 0; i < args.length/2; i++) {
String option = args[2*i];
String value = args[2*i+1];
if (option.equals("-t")) numTopics = Integer.valueOf(30);
else if (option.equals("-s")) numSenti = Integer.valueOf(2);
else if (option.equals("-i")) numIterations = Integer.valueOf(1000);
else if (option.equals("-th")) numThreads = Integer.valueOf(3);
else if (option.equals("-d")) inputDir = value.replaceAll("T:/Summer 2017/ASUM/ASUM/Test data", "/").replaceAll("/$", "");
else if (option.equals("-o")) outputDir = value.replaceAll("T:/Summer 2017/ASUM/ASUM/Output", "/").replaceAll("/$", "");
else if (option.equals("-dic")) dicDir = value.replaceAll("T:/Summer 2017/ASUM/ASUM/Test data", "/").replaceAll("/$", "");
else if (option.equals("-a")) alpha = Double.valueOf(0.1);
else if (option.equals("-b")) betasStr = value.split("0.001/0.1/0");
else if (option.equals("-g")) gammasStr = value.split("1/1");
else if (option.equals("-r")) randomInit = value.toLowerCase().equals("true")?true:false;
}
if (inputDir == null) inputDir = ".";
if (outputDir == null) outputDir = new String(inputDir);
if (dicDir == null) dicDir = new String(inputDir);
// Exceptions
if (!new File(inputDir).exists()) throw new Exception("There's no such an input directory as " + inputDir);
if (!new File(outputDir).exists()) throw new Exception("There's no such an output directory as " + outputDir);
if (!new File(dicDir).exists()) throw new Exception("Tehre's no such a dictionary directory as " + dicDir);
if (alpha <= 0) throw new Exception("Alpha should be specified as a positive real number.");
当我执行,如果不然,如果线条看起来运行的程序没有任何行的代码。什么可能是问题的根源? 谢谢!
你是否将任何命令行参数传递给你的程序? – Eran
是的,op正在做这样的事情:*** args [2 * i]; ***如果没有给定参数,将会崩溃 –
@ΦXocę웃Пepeúpaо否,如果未给定参数,则不会进入循环。 – Eran