按钮监听事件:(传递用户名和密码到服务器端)
mButton2.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
String id = mEditText1.getText().toString();
String pwdFld = mEditText2.getText().toString();
if (mEditText1.getText().length() == 0 || mEditText2.getText().length() == 0)
{
toast();
mEditText1.setText(" ");
mEditText2.setText(" ");
}else{
//发送用户输入的用户名和密码给服务器
Request req = new Request();
req.setAction("userLogin");
req.setAttribute("id", id);
req.setAttribute("pwdFld", pwdFld);
System.out.println(id+ pwdFld);
System.out.println(req.getAttribute("id"));
System.out.println(req.getAttribute("pwdFld"));
//获取响应
Response response = null;
try {
response = ClientUtil.sendTextRequest(req);
一下部分代码省略......
出现空指针异常的地方用红色标出。
public static Response sendTextRequest(Request request) throws IOException {
Response response = null;
try {
// 发送请求
System.out.println(request.getAttribute("id"));
System.out.println(request.getAttribute("pwdFld"));
ClientDataBuffer.oos.writeObject(request);
ClientDataBuffer.oos.flush();
System.out.println("客户端发送了请求对象:" + request.getAction());
mButton2.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
String id = mEditText1.getText().toString();
String pwdFld = mEditText2.getText().toString();
if (mEditText1.getText().length() == 0 || mEditText2.getText().length() == 0)
{
toast();
mEditText1.setText(" ");
mEditText2.setText(" ");
}else{
//发送用户输入的用户名和密码给服务器
Request req = new Request();
req.setAction("userLogin");
req.setAttribute("id", id);
req.setAttribute("pwdFld", pwdFld);
System.out.println(id+ pwdFld);
System.out.println(req.getAttribute("id"));
System.out.println(req.getAttribute("pwdFld"));
//获取响应
Response response = null;
try {
response = ClientUtil.sendTextRequest(req);
一下部分代码省略......
出现空指针异常的地方用红色标出。
public static Response sendTextRequest(Request request) throws IOException {
Response response = null;
try {
// 发送请求
System.out.println(request.getAttribute("id"));
System.out.println(request.getAttribute("pwdFld"));
ClientDataBuffer.oos.writeObject(request);
ClientDataBuffer.oos.flush();
System.out.println("客户端发送了请求对象:" + request.getAction());
解决方案 »
- jni编译错误:Native registration unable to find class
- Android 应用程序反应慢
- NDK环境编译提示找不到 AttachCurrentThread
- 在android2.3.4中如何通过修改framework,让所有应用都竖屏显示
- [求助]android里如何判断手机的sim卡类型
- 关于精灵移动的问题
- android 如何定制视频大小
- 如何在andriod应用层获取一个比屏幕长宽都大的坐标值?
- 安卓的数据存储跟JAVA的数据存储的区别
- xmpp协议的安卓消息推送Androidpn的client端出现xmpp连接失败
- 几个android本科毕业设计选题的技术要点分析。
- 求一本比较全面介绍android网络编程的书
11-11 02:02:02.389: ERROR/AndroidRuntime(415): java.lang.NullPointerException
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at com.Client.ClientUtil.sendTextRequest(ClientUtil.java:24)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at com.Client.ClientActivity$2.onClick(ClientActivity.java:83)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at android.view.View.performClick(View.java:2485)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at android.view.View$PerformClick.run(View.java:9080)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at android.os.Handler.handleCallback(Handler.java:587)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at android.os.Handler.dispatchMessage(Handler.java:92)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at android.os.Looper.loop(Looper.java:123)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at java.lang.reflect.Method.invokeNative(Native Method)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at java.lang.reflect.Method.invoke(Method.java:507)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-11 02:02:02.389: ERROR/AndroidRuntime(415): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
这个什么OOS在哪里实例化的或者在哪里获取的?确定这个对象不为空么?
public static ObjectOutputStream oos;/** 当前客户端连接到服务器的输出流 */
/** 客户端数据缓存 */
public class ClientDataBuffer
{
public static String currentUser; /** 当前客户端的用户信息 */
public static String onlineUsers;/** 在线用户列表 */
public static Socket clientSocket;/** 当前客户端连接到服务器的套节字 */
public static ObjectOutputStream oos;/** 当前客户端连接到服务器的输出流 */
public static ObjectInputStream ois;/** 当前客户端连接到服务器的输入流 */
public static Properties configProp;/** 服务器配置参数属性集 */
//public static Dimension screenSize;/** 当前客户端的屏幕尺寸 */
public static String ip ;/** 本客户端的IP地址 */
public static final int RECEIVE_FILE_PORT = 6666;/** 用来接收文件的端口 */
static{
//screenSize = Toolkit.getDefaultToolkit().getScreenSize();
configProp = new Properties();//加载服务器配置文件
try {
ip = InetAddress.getLocalHost().getHostAddress();
configProp.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("serverconfig.properties"));
} catch (IOException e) {e.printStackTrace();}
}
private ClientDataBuffer(){
}
}
ClientDataBuffer.oos.writeObject(request);
ClientDataBuffer.oos.flush();这样算不算实例化了呢?
public static Response sendTextRequest(Request request) throws IOException {
Response response = null;
try {
// 发送请求
ObjectOutputStream oos;
oos.writeObject(request);
oos.flush();
System.out.println("客户端发送了请求对象:" + request.getAction());
可是还是出现上面的异常