I'm trying to move a Java project I've made and tested to Android. My problem appears when I create the Socket with the Strings for the IP and port (which are not null and correspond to the IP of an open and working server). A NullPointerException appears. The code is an AsyncTask that is activated when the user presses a button. This is the doInBackground method:
@Override
protected Void doInBackground(String... strings) {
client = new Client(strings[0]);
DataStorage.getInstance().setClient(client);
try {
boolean a = client.connectToServer(strings[0]); //It dies here
if (!(un).equals("")&&a) {
Toast.makeText(context,"Connected",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context, AvailableClientsActivity.class);
context.startActivity(intent);
} else {
Toast.makeText(context,"Username invalid",Toast.LENGTH_SHORT).show();
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
client.resetConnection();
}
return null;
}
This is the message I get Method threw 'java.lang.NullPointerException' exception. Cannot evalueate android.system.StructAddrinfo.toString()
I've just started with Android so it might be something basic I've skipped.