0

I have been working on a program to control an L.E.D. matrix with a RaspberryPi 3B+ and I wanted to structure my program so each Matrix would be an array of MatrixComponents.

package matrixcontroller;

public class MatrixComponent throws Exception{

    private String componentMode; // Defines whether component is an input or output device.
    private String controlType; // For recalling whether component is analog, binary, or PWM.

    public MatrixComponent(String componentMode, String controlType) {
        if (componentMode.toUpperCase().equals("INPUT")) this.componentMode = "INPUT";
        else if (componentMode.toUpperCase().equals("OUTPUT")) this.componentMode = "OUTPUT";
        else throw new InvalidComponentModeException("'" + componentMode + "' is not a valid component mode.");
    }
}

This is what I have started working on so far, but my IDE (Netbeans) is telling me that InvalidComponentModeException is not a class. The problem is that I have a InvalidComponentModeException class in the same package, so I am confused as to why it is not working. Any ideas?

package matrixcontroller;

public class InvalidComponentModeException extends RuntimeException {

    public InvalidComponentModeException(){
        super();
    }

    public InvalidComponentModeException(String message){
        super(message);
    }
}
  • 3
    `public class MatrixComponent throws Exception{` ? – Bruno May 19 '17 at 16:56
  • 1
    Yeah @BrunoDM points to the issue, move that `throws Exception` from the class declaration to the constructor declaration... or better, just remove it. – Hugues M. May 19 '17 at 17:00
  • That is embarrassing, thankyou for the help! – TheMountainFurnaceGabriel May 19 '17 at 17:04
  • Maybe the definition for your classpath in Netbeans is not quite right. I tried your code (after having already fixed the "throws Exception") compiling it on the command line `javac matrixcontroller/MatrixComponent.java` and got the error you mentioned (I was in the parent directory of the matrixcontroller dir). Adding the classpath fixed the compile error `javac -classpath . matrixcontroller/MatrixComponent.java` – Stephen P May 19 '17 at 17:08

0 Answers0