0

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"

3
  • 1
    Seems like that method is in DTNode. Commented Apr 9, 2014 at 21:11
  • You either need to run that method on a DTNode instance, or create the method in your own class. Commented Apr 9, 2014 at 21:11
  • thank you guys, I just had to run it on the instance Commented Apr 9, 2014 at 21:13

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.