我们正在研究数据挖掘项目,问题是在指定代码中无法访问对象Mode。谁能解释代码中的问题?
try{
String query = "select algm from accuracy where id=1";
PreparedStatement pst = connection.prepareStatement(query);
ResultSet rs = pst.executeQuery();
alg = rs.getString("algm");
pst.execute();
pst.close();
}catch(Exception e1){
JOptionPane.showMessageDialog(null,e1);
}
if(alg.equals("DecisionStump"))
{
DecisionStump Mode = new DecisionStump();
}
else if(alg.equals("NaiveBayes"))
{
NaiveBayes Mode = new NaiveBayes();
}
// filter for removing samples:
Remove rm = new Remove();
rm.setAttributeIndices("1"); // remove 1st attribute
// filtered classifier
FilteredClassifier fc = new FilteredClassifier();
fc.setFilter(rm);
fc.setClassifier(Mode); //This object Mode is not accesible
您Mode
在if或else if语句中声明该对象,并在不再可用的上下文外部(块范围)使用该对象。
您可以执行以下操作:
Classifier Mode; // a parent class
if(alg.equals("DecisionStump")) {
Mode = new DecisionStump();
} else if(alg.equals("NaiveBayes")) {
Mode = new NaiveBayes();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句