Here's the error I'm getting:
I know it's telling me that a[0].setAttribute(0); is wrong, but I don't know why it's wrong. How should I be filling up the Instance array with values?
java.lang.NullPointerException
at DecisionTree.TestTree.main(TestTree.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
This is the class I'm using to test my constructors.
package DecisionTree;
public class TestTree {
public static void main(String[] args) {
Instance[] a = new Instance[5];
a[0].setAttribute(0);
a[1].setAttribute(1);
a[2].setAttribute(2);
a[3].setAttribute(3);
a[4].setAttribute(4);
a[0].setLabel(true);
a[1].setLabel(false);
a[2].setLabel(true);
a[3].setLabel(false);
a[4].setLabel(true);
DecisionTree work = new DecisionTree(a);
System.out.println(work.root.cutoff);
}
}
The instance class:
package DecisionTree;
public class Instance {
double attribute;
boolean label;
public Instance(double a, boolean c) {
attribute = a;
label = c;
}
public double getAttribute() {
return attribute;
}
public void setAttribute(double a) {
attribute = a;
}
public boolean getLabel() {
return label;
}
public void setLabel(boolean c) {
label = c;
}
}
null) ina[0], since you didn't put anything there.