Click here to Skip to main content
Sign Up to vote bad
good
See more: Java
Android. Java.Lang.NullPointerException execiting this code:
try{
//sc.setReceiveBufferSize(163840);
sc = new Socket("46.247.186.175", 8090);
SocketAddress sa = new InetSocketAddress("46.247.186.175", 8090);
sc.connect(sa);
   }catch(Exception x)
   {
       logn.setText(x.toString());//Java.Lang.NullPointerException, Why?

   }
EDIT: logn is declared in OnCreate func and I wrote "EditText logn;" in the Class
EDIT2: I have commented "sc.setReceiveBufferSize(163840);", so now app crashing without any exceptions.
Posted 12-Nov-12 7:14am
halabella1.3K
Edited 12-Nov-12 20:30pm


2 solutions

Apparently, because logn is null at this point. Look at your code and find out why. Should you have a smallest concern about your runtime behavior, always use the debugger.
 
—SA
  Permalink  
I second Sergey's answer, the Socket Connection is failing.
 
You should also write that different:
 
try{
  sc.setReceiveBufferSize(163840);
  sc = new Socket("46.247.186.175", 8090);
  SocketAddress sa = new InetSocketAddress("46.247.186.175", 8090);
  sc.connect(sa);
}
catch(Exception x) {
       System.out.println(x.printStackTrace()); // to get the full exception
   }
 
I also recommend better naming of variables - you will loose track with sc/sa/s... . Name them "socket" and "address" and so on.
  Permalink  
Comments
halabella - 12-Nov-12 15:17pm
By adding "System.out.println(x.printStackTrace());" I got an error: "The method printIn(void) is undefined for the type PrintStream", what to do with this?
TorstenH. - 12-Nov-12 15:21pm
maybe you should try desktop java development first.
halabella - 12-Nov-12 15:38pm
I'm not understood you. I want to rewrite my totally worked JavaME app for Android. I have edited my post

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 6,889
1 Prasad_Kulkarni 3,671
2 OriginalGriff 3,359
3 _Amy 3,312
4 CPallini 2,925


Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid