user3059662
user3059662

Reputation: 37

Java, method undefined for type, despite being in same package

Im trying to construct a deciscion tree with many method, but any time I try to reference a class in the same package, it won't recognize the methods within.

code:

public void generateBranches(DTNode parent) 
    {
        double minEntropy = 2.0; 
        boolean y = false;
        int j = 0;
        ArrayList<Double> Entropyvalues = new ArrayList<Double>(parent.a.length);
        //int boolean tmp = parent.a[0].getlabel();
        for (int i = 0 ;i < parent.a.length ; i++) {
            if (parent.a[i].label != parent.a[j].label) 
            {   
             Double Tempropy = InstanceEntropy(childInstance(parent,i,j)); 
//error here, childInstance succesfully returns an instance[] array
             Entropyvalues.add(Tempropy);
        } 
        }
        //DTNode LChild = newDTnode()

here is the method (and the class) Im trying to call:

package DecisionTree;

import java.lang.*;

public class DTNode {
    Instance[] a; 
    double testValue;    
    DTNode left, right;


    public  DTNode(Instance[] b)
    {   
        a = b; 
    }


    public Double InstanceEntropy(Instance[] a)
    {
        DTNode tmp = new DTNode(a); 
        return tmp.entropy(tmp);

    }

and the error: "the method InstanceEntropy(Instance[]) is undefined for type DecisionTree"

Upvotes: 0

Views: 589

Answers (1)

Kon
Kon

Reputation: 10810

Yes, your method is in the same package so it can be SEEN by your caller, but it must be references with an object. The method is non-static and belongs to another class. Try something like

Double Tempropy = new DTNode(..).InstanceEntropy(..)

Also I would consider reading up on proper Java naming conventions becuase yours are pretty nonstandard.

NOTE: As per @Bhesh Gurung, you need to provide a proper Instance array constructor to DTNode

Upvotes: 2

Related Questions