Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 8:14am
Edited 12-Nov-12 21:30pm
v6
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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 at 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. at 12-Nov-12 15:21pm
   
maybe you should try desktop java development first.
halabella at 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
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100