我正在编写一个应用程序,允许我通过单击按钮通过 TCP/IP 发送命令。但是,当我单击模拟器中的按钮时,它会返回一条消息,说明该按钮已停止工作。我想知道是否有人能在我的代码中发现错误。
代码:
package button.test;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class ButtonActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View view) throws UnknownHostException, IOException
{
Socket socket = new Socket("192.168.2.92", 60128);
try{
dataOutputStream.Object BUFFER = null;
write(BUFFER);
String buffer="ISCP000000100000000701000000!1PWR010D";
OutputStream os=socket.getOutputStream();
os.write(buffer.getBytes());
} catch(IOException e)
{
//error code
}
}
private void write(Object BUFFER) {
// TODO Auto-generated method stub
}
}