I am trying to use a Weka method, crossValidateModel, which is posted in the last. It looks like that the fifth parameter is referred to as varargs parameter. I tried the example usage given in Weka page, such as

eval.crossValidateModel(cls, data, folds, rand);

It works just fine on one system,(eclipse+Ubuntu); but it fails on other system (RedHat Eclipse+Centos). The Eclipse gives the following message

The method crossValidateModel(Classifier, Instances, int, Random, Object[]) in the type Evaluation is not applicable for the arguments (Classifier, Instances, int, Random)

I think this problem comes from the existence of varargs parameter, but I do not know why. Thanks for the explanation.

/**
             * Performs a (stratified if class is nominal) cross-validation
             * for a classifier on a set of instances. Now performs
             * a deep copy of the classifier before each call to
             * buildClassifier() (just in case the classifier is not
             * initialized properly).
             *
             * @param classifier the classifier with any options set.
             * @param data the data on which the cross-validation is to be
             * performed
             * @param numFolds the number of folds for the cross-validation
             * @param random random number generator for randomization
             * @param forPredictionsPrinting varargs parameter that, if supplied, is
             * expected to hold a weka.classifiers.evaluation.output.prediction.AbstractOutput
             * object
             * @throws Exception if a classifier could not be generated
             * successfully or the class is not defined
             */
            public void crossValidateModel(Classifier classifier,
                    Instances data, int numFolds, Random random,
                    Object... forPredictionsPrinting) throws Exception {

                // Make a copy of the data we can reorder
                data = new Instances(data);
                data.randomize(random);
                if (data.classAttribute().isNominal()) {
                    data.stratify(numFolds);
                }

                // We assume that the first element is a
                // weka.classifiers.evaluation.output.prediction.AbstractOutput object
                AbstractOutput classificationOutput = null;
                if (forPredictionsPrinting.length > 0) {
                    // print the header first
                    classificationOutput = (AbstractOutput) forPredictionsPrinting[0];
                    classificationOutput.setHeader(data);
                    classificationOutput.printHeader();
                }

                // Do the folds
                for (int i = 0; i < numFolds; i++) {
                    Instances train = data.trainCV(numFolds, i, random);
                    setPriors(train);
                    Classifier copiedClassifier = AbstractClassifier
                            .makeCopy(classifier);
                    copiedClassifier.buildClassifier(train);
                    Instances test = data.testCV(numFolds, i);
                    evaluateModel(copiedClassifier, test,
                            forPredictionsPrinting);
                }
                m_NumFolds = numFolds;

                if (classificationOutput != null)
                    classificationOutput.printFooter();
            }

Variable arity (var-args) are a Java 5+ feature but is implemented under the hood as an array. If you have a Java 1.4 compiler trying to compile the code calling a var args method, there is a possibility of getting this error. Are you sure the setup on CentOS (both Eclipse and Java installation) is using Java 5+ ?

Here is the result of my running "java -version"
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) 64-Bit Server VM (build 11.0-b15, mixed mode)


Is there anything wrong with this? Thanks.

Variable arity (var-args) are a Java 5+ feature but is implemented under the hood as an array. If you have a Java 1.4 compiler trying to compile the code calling a var args method, there is a possibility of getting this error. Are you sure the setup on CentOS (both Eclipse and Java installation) is using Java 5+ ?

> Is there anything wrong with this? Thanks.

No, looks good. Do you have multiple Java versions installed? If yes, can you check which one is used by Eclipse? Also, can you check that the compiler compliance level for your project in Redhat Eclipse is >= 1.5 by going to "right click project -> properties -> java compiler"? Also, can you try compiling the class mentioned in your first post using the command line "javac" rather than using Eclipse?

Edited 4 Years Ago by ~s.o.s~: n/a

Hi, by following "right click project -> properties -> java compiler", the information window is like

Under the JDK Compilance panel

Compiler Compilance Level : 1.4

> Is there anything wrong with this? Thanks.

No, looks good. Do you have multiple Java versions installed? If yes, can you check which one is used by Eclipse? Also, can you check that the compiler compliance level for your project in Redhat Eclipse is >= 1.5 by going to "right click project -> properties -> java compiler"? Also, can you try compiling the class mentioned in your first post using the command line "javac" rather than using Eclipse?

That's a problem because when compiling for 1.4 target VM, the compiler doesn't know about var args. The solution is to change the compliance to at least 1.5 (1.6 would be recommended). I would suggest to change the workspace compliance level and make sure you don't override workspace specific compliance when creating a new project.

In Eclipse go to: Window -> Preferences -> Java -> Compiler -> JDK Compliance -> Change drop down to 1.6 and check the 'Use default compliance settings'.

For your project, right click -> properties -> Java Compiler -> uncheck enable project specific settings -> OK

Edited 4 Years Ago by ~s.o.s~: n/a

This question has already been answered. Start a new discussion instead.