对象在java代码中不可访问

对象在java代码中不可访问,java,Java,我们正在进行数据挖掘项目。问题是在指定的代码中无法访问对象模式。有人能解释代码中的问题吗 try{ String query = "select algm from accuracy where id=1"; PreparedStatement pst = connection.prepareStatement(query); ResultSet rs = pst.executeQuery();

我们正在进行数据挖掘项目。问题是在指定的代码中无法访问对象模式。有人能解释代码中的问题吗

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

您正在if或else if语句内声明
模式
对象,并在其不再可用的上下文(块范围)外使用相同的对象

您可以执行以下操作:

Classifier Mode; // a parent class
if(alg.equals("DecisionStump")) {
  Mode = new DecisionStump();
} else if(alg.equals("NaiveBayes")) {
  Mode = new NaiveBayes();
}

标识符
模式
正在一个本地块中声明,该块立即退出的作用域

        Classifier mode
        if(alg.equals("DecisionStump"))
        {
            mode = new DecisionStump();

        }
        else if(alg.equals("NaiveBayes"))
        {
            mode = new NaiveBayes();
        }

能否显示
FilteredClassifier
的包名?可能它必须是
FilteredClassifier.MODE
?weka.classifiers.meta.FilteredClassifier.FilteredClassifier()代码是特定于块的,无法在外部访问。根据Java语言约定,变量使用小写名称。此外,请阅读变量范围,并使用适当的tagd。生活中有许多事情我不明白!现在,对这个答案投反对票就是其中之一。我认为这次反对票是针对这个问题的。有人否决了答案P@codeMan,只要投一票,你就可以否定5件你不懂的事情。就我个人而言,我认为有些人过于重视声誉的游戏激励。