I make some classification program with weka api of java and
I use weka's default contact-lens.arff
data set.
I've completed the code and it runs well with one exception.
import weka.core.Instances;
import weka.classifiers.rules.OneR;
import weka.classifiers.trees.J48;
import weka.classifiers.bayes.NaiveBayes;
/*
~ some codes ~
*/
static OneR or_lens = new OneR();
static J48 tree_lens=new J48();
static NaiveBayes nb_lens = new NaiveBayes();
static OneR or_weather = new OneR();
static J48 tree_weather=new J48();
static NaiveBayes nb_weather = new NaiveBayes();
public static void lens_learning(Instances lens_data) {
try {
or_lens.buildClassifier(lens_data); // occur exception
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
~ some codes ~
*/
java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @4dcbadb4
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at weka.core.WekaPackageClassLoaderManager.injectClasses(WekaPackageClassLoaderManager.java:792)
at weka.core.WekaPackageClassLoaderManager.injectAllClassesInFromStream(WekaPackageClassLoaderManager.java:690)
at weka.core.WekaPackageClassLoaderManager.injectMTJCoreClasses(WekaPackageClassLoaderManager.java:118)
at weka.core.WekaPackageManager.<clinit>(WekaPackageManager.java:255)
at weka.core.ResourceUtils.readProperties(ResourceUtils.java:241)
at weka.core.ResourceUtils.readProperties(ResourceUtils.java:184)
at weka.core.Utils.readProperties(Utils.java:183)
at weka.core.Capabilities.<clinit>(Capabilities.java:104)
at weka.classifiers.AbstractClassifier.getCapabilities(AbstractClassifier.java:509)
at weka.classifiers.rules.OneR.getCapabilities(OneR.java:289)
at weka.classifiers.rules.OneR.buildClassifier(OneR.java:317)
at hw2.Hw2.lens_learning(Hw2.java:25)
at hw2.Hw2.main(Hw2.java:102)
After it occurs this Runtime Exception, program runs smoothly.
But, I want to hide or get rid of this exception strings.
I use jdk-17.0.1
.
Why
buildClassifier
occurs this exception?How can I hide this exception strings?
try ... catch ...
couldn't hide them :,(
CodePudding user response:
At the time of writing, Weka's package manager does not work with Java 16 or later (due to low-level class injections). Use Java 11 instead.