XML文件布局:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TextView android:id="@+id/TextView" android:singleLine="false"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
- <EditText android:hint="content" android:id="@+id/EditText01"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </EditText>
- <Button android:text="login" android:id="@+id/Button01"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- <Button android:text="send" android:id="@+id/Button02"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Button>
- </LinearLayout>
先启动服务器端,再运行客户端程序。
注意:(一)即使服务器端和客户端在一台机器上运行,也不能使用ip地址:127.0.0.1,否则,程序会出现拒绝连接的错误。
(二)客户端和服务器端最好不要建在一个工程下,最好是分别建立工程,然后启动服务器端和客户端,否则会报Error: ShouldNotReachHere()错误。这是因为Android程序不是已main方法为程序的入口。
运行效果:


