我正试图将java的袖珍客户安装在roid,我的服务器是我的手提电脑。 我想我和roid的机动车用java的袖珍连接手提电脑。 但是,在客户方面,我却感到有例外:“欢迎”,而我看上去是因为呼吁书状无法适当编造。 下面是供审查的我的和roid客户旁码。 是否解决了这一例外情况:
public class SimpleActivityExampleActivity extends Activity {
/** Called when the activity is first created. */
private String usrName;
private String vendorName;
private String message;
public Socket socket;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void submitTheForm(View view) {
final EditText edittext1 = (EditText) findViewById(R.id.editText1);
final EditText edittext2 = (EditText) findViewById(R.id.EditText01);
final EditText edittext3 = (EditText) findViewById(R.id.editText2);
usrName = edittext1.getText().toString();
vendorName = edittext2.getText().toString();
message = edittext3.getText().toString();
message = usrName+ "," + vendorName + "," + message;
byte[] msg = message.getBytes();
try {
InetAddress serverAddr = InetAddress.getByName("192.168.1.2");
Log.d("ClientActivity", "C: Connecting...");
socket = new Socket(serverAddr, 2200);
socket.getOutputStream().write(msg);
socket.getOutputStream().flush();
} catch (UnknownHostException e) {
Toast.makeText(SimpleActivityExampleActivity.this, "unknownhostException", Toast.LENGTH_SHORT).show();
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SocketException e) {
// TODO Auto-generated catch block
Toast.makeText(SimpleActivityExampleActivity.this, "Sockexception", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
//System.out.println("in IOexception for sure");
Toast.makeText(SimpleActivityExampleActivity.this, "IOexception", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
catch (Exception e){
Toast.makeText(SimpleActivityExampleActivity.this, "Exception", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}finally {
if(socket != null){
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
提交 TheForm () function isquot on a button Point from main.xml file “android:onClick = “submitTheForm”