I am trying to establish a bluetooth connection between my Android app (the client) and my python server. However, I have got a problem with the streams. This piece of code throws a ClassCastException
and I don't know why and how to fix it. Any ideas or tips?
public ConnectedThread(BluetoothSocket socket) {
Log.d(TAG, "create ConnectedThread");
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
// Get the BluetoothSocket input and output streams
try {
// THIS IS WHERE THE EXCEPTION IS THROWN
tmpIn = (DataInputStream) socket.getInputStream();
tmpOut = (DataOutputStream) socket.getOutputStream();
} catch (IOException e) {
Log.e(TAG, "temp sockets not created", e);
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
}