套接字给我错误是null [英] Socket give me error is null

查看:112
本文介绍了套接字给我错误是null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好吗



其实我在Android(Eclipse)客户端服务器上做了应用程序,但编译器在这个声明中给了我错误





Hi everone

Actually I did app in Android (Eclipse) client server, but the compiler give me error
in this statement:

try{
     Socket s = new Socket(IPAddress,PORT);
   }catch(Exception e){
       Log.e("Exception", e.getMessage());
   }





错误是



the error is

println needs a message





对不起英语



sorry for English

推荐答案

你需要确保传递给 Log.e 的第二个参数不为空。

一种方法是检查 e。 getMessage()并记录其他内容,如果它为null;

You need to make sure the second argument passed to Log.e isn't null.
One way to do that would be to inspect e.getMessage() and log something else if it is null;
try {
  Socket s = new Socket(IPAddress,PORT);
} catch(Exception e){
  String message = e.getMessage() == null ? e.toString() : e.getMessage();
  Log.e("Exception", e.getMessage());
}





希望这会有所帮助,

Fredrik



Hope this helps,
Fredrik


这篇关于套接字给我错误是null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆