获得不兼容的类型错误

时间:2017-11-23 18:42:38

标签: java data-mining decision-tree

Hello其他程序员。我正在学习Java作为一种潜在的职业道路,但我现在正把它作为一种爱好(因为缺乏一个更好的词);即使我不认为自己是初学者,但我遇到的问题是我认为是由于某些原因我无法弄清楚的简单错误。

以下是我关注的代码:

import java.io.*;

import java.util.*;

public class ID3
{

        int []array = new int[values.size()];
        for (int i=0; i< array.length; i++) {
            String symbol = (String)values.elementAt(i);
            array = domains[attribute].indexOf(symbol);//Type Error
        }
        values = null;
        return array;
    }

    public void decomposeNode(TreeNode node) {
        double bestEntropy=0;
        boolean selected=false;
        int selectedAttribute=0;
        int numdata = node.data.size();
        int numinputattributes = numAttributes-1;
        node.entropy = calculateEntropy(node.data);
        if (node.entropy == 0) return;

        for (int i=0; i< numinputattributes; i++) {
            int numvalues = domains.size(); //Cannot resolve method (?)
            if ( alreadyUsedToDecompose(node, i) ) continue;
            double averageentropy = 0;
            for (int j=0; j< numvalues; j++) {
                Vector subset = getSubset(node.data, i, j);
                if (subset.size() == 0) continue;
                double subentropy = calculateEntropy(subset);
                averageentropy += subentropy *
                        subset.size();
            }




        domains = new Vector[numAttributes];
    for (int i=0; i < numAttributes; i++) domains = new Vector();//TYPE ERROR
        attributeNames = new String[numAttributes];
        for (int i=0; i < numAttributes; i++) {
            attributeNames = tokenizer.nextToken(); //TYPE ERROR
        }

        .....

            DataPoint point = new DataPoint(numAttributes);

            for (int i=0; i < numAttributes; i++) {

                point.attributes = getSymbolValue(i, tokenizer.nextToken()//TYPE ERROR
                );
            }
            root.data.addElement(point);
        }
        bin.close();
        return 1;
    }


        int numvalues = node.children.length;
        for (int i=0; i < numvalues; i++) {
            System.out.println(tab + "if( " +
                    attributeNames[node.decompositionAttribute] + " == \"" +
                    domains[node.decompositionAttribute].elementAt(i)
                    + "\") {" );
            printTree(node.children, tab + "\t"); //Incompatible types
            if (i != numvalues-1) System.out.print(tab + "} else ");
            else System.out.println(tab + "}");
        }
    }

    public void createDecisionTree() {
       .....
    }

我收到以下错误:

Error:(368, 57) java: incompatible types: java.util.Vector cannot be converted to java.util.Vector[]
Error:(374, 49) java: incompatible types: java.lang.String cannot be converted to java.lang.String[]
Error:(410, 50) java: incompatible types: int cannot be converted to int[]
Error:(449, 71) java: incompatible types: int[] cannot be converted to int
Error:(473, 27) java: incompatible types: ID3.TreeNode[] cannot be converted to ID3.TreeNode

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

[]符号只能用于数组

String[] array = "error";

不编译,因为左侧的类型是向量的数组,而右侧只有单个字符串。