I have a problem. I created a TCP client that executes in the new thread connection with Server. Unfortunately, the program shuts down. In LogCat I get the following message:
"FATAL EXCEPTION: Thread-14635 Process: com.example.sebastian.ravia, PID: 8648 java.lang.NullPointerException: Attempt to invoke a virtual method 'android.os.Bundle android.content.Intent.getExtras () on a null object reference at com.example.sebastian.ravia.ClientThread.run (TcpClient.java:36) at java.lang.Thread.run (Thread.java:818)
The problem is in: "Bundle przekazanedane". With this bundle I download the text to String of EditText from the previous Activity.
Here's the code:
public class TcpClient extends Activity {
//private Socket socketIn;
//private Socket socketOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.client_activity);
new Thread(new ClientThread()).start();
} }
class ClientThread extends TcpClient implements Runnable {
private boolean aRun = false;
private String aHost;
private String aSocketIn;
private String aSocketOut;
public void run() {
Bundle przekazanedane = getIntent().getExtras();
if(przekazanedane != null) {
aHost = przekazanedane.getString("addressIp");
aSocketIn = przekazanedane.getString("socketIn");
aSocketOut = przekazanedane.getString("socketOut");
}
int aSocketInInt;
int aSocketOutInt;
aRun = true;
aSocketInInt = Integer.parseInt(aSocketIn);
aSocketOutInt = Integer.parseInt(aSocketOut);
try {
InetAddress serwerAddress = InetAddress.getByName(aHost);
Socket socket = new Socket(serwerAddress, aSocketInInt);
PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
}
catch (Exception e) {
e.printStackTrace();
}
} }