Saket Khandelwal Saket Khandelwal - 1 year ago 42
Android Question

Cannot Resolve Method 'newDataOutputStream'

I am getting an cannot resolve method error when i do this:

DataOutputStream os = newDataOutputStream(client.getOutputStream());


My imports:

import android.os.Bundle;
import android.app.Activity;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.text.format.Formatter;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;


Code for class

@SuppressWarnings("deprecation")
class sentMessage implements Runnable {
public void run() {
try {
Socket client = serverSocket.accept();
DataOutputStream os = newDataOutputStream(client.getOutputStream());
str = smessage.getText().toString();
msg = msg + "\n Server : " + str;

handler.post(new Runnable() {
public void run() {
chat.setText(msg);
}
});
os.writeBytes(str);
os.flush();
os.close();
client.close();
} catch (IOException e) {
}
}
}

Answer Source

You're missing a space.

DataOutputStream os = new DataOutputStream(client.getOutputStream());
                         ^
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download