Click here to Skip to main content
15,028,757 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
Hi everone

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

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


the error is
Java
println needs a message


sorry for English
Posted
Comments
   
Not error. Exception. I cannot believe this is the exception thrown by the code shown. Also, output the exception class name, not just message; at least.
—SA
Ammar Al-hamdabni 22-Sep-14 2:35am
   
thanks for response, Ok No Problem but when compiler give you null exception what does that mean.
   
It means that this is one of the simplest problem for the debugging. You are trying to dereference some object by using on of its instance members, while it is actually null. Fix it by checking the variable/member for null, do something else if it is; check up if you could miss initialization of the object.
—SA
Fredrik Bornander 22-Sep-14 3:39am
   
Log is a class, e is a static method on Log, he's passing null as the second parameter and e does not like that.
   
Ah, my bad... Than you very much.
—SA

1 solution

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;
Java
try {
  Socket s = new Socket(IPAddress,PORT);
} catch(Exception e){
  String message = e.getMessage() == null ? e.toString() : e.getMessage();
  Log.e("Exception", e.getMessage());
}


Hope this helps,
Fredrik
   
Comments
   
5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900