I am trying to create a connection and subclass it so that i can use it for both Bluetooth and USB but am having a little problem Here are the codes:
superclass:
- Code: Select all
public class Connection {
// private data members
protected NXTConnector connection;
protected DataInputStream dataInput;
protected DataOutputStream dataOutput;
public void initialize(){
this.connection = new NXTConnector();
this.dataInput = null;
this.dataOutput = null;
}
public Connection() {
this.initialize();
}
// other code here ....
}
subclass:
- Code: Select all
public class BluetoothConnection extends Connection{
public void initialize(){
boolean connected = this.connection.connectTo("btspp://");
// Connect to any NXT over Bluetooth
if (!connected) {
System.err.println("Failed to connect to any NXT");
System.exit(1);
}
this.setDataInput(this.getConnection().getDataIn());
this.setDataOutput(this.getConnection().getDataOut());
}
public BluetoothConnection() {
// superclass constructor called to initiate the NXTConnector
super();
this.initialize();
}
I always get the "Failed to connect to any NXT" message.
Is it not possible to subclass the NXTConnector class?
Need help.
thanks[/code]
