receiving value from python server on android app client and then displaying data from mysql corresponding to the value










0















I'm getting to receive data from Python server on android client, and i'm storing the data in a variable called Answerfromserver. After that I'm using the Answerfromserver to retrieve data from wamp database. Now when i install the app on my phone, what happens is that when i get the correct data for retrieval from wamp, so my app crashes. I'm attaching my app code, please help me on this..



Edit - I commented out the execute of the code where the data is received from the mysql wamp server, so in that case my app is correctly displaying the data from python server, but i comment out the execute of the python server code app crashes..



package marecki.androidsocketclient;

import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.URLEncoder;
import java.net.UnknownHostException;

import static java.io.DataInputStream.readUTF;

public class MainActivity extends AppCompatActivity

TextView textAnswer;
Button buttonConnect;
EditText editTextIP, editTextPort, message;
ProgressBar progressBar;
String result="";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textAnswer = (TextView)findViewById(R.id.text_answer);
buttonConnect = (Button)findViewById(R.id.connect);
editTextIP = (EditText)findViewById(R.id.address);
editTextPort = (EditText)findViewById(R.id.port);
message = (EditText)findViewById(R.id.edit_message);

progressBar = (ProgressBar)findViewById((R.id.progressBar));
progressBar.setVisibility(ProgressBar.INVISIBLE);

buttonConnect.setOnClickListener(buttonConnectOnClickListener);


OnClickListener buttonConnectOnClickListener = new OnClickListener()

@Override
public void onClick(View arg0)

String Msg = message.getText().toString();

ClientTask clientTask = new ClientTask(
editTextIP.getText().toString(),
Integer.parseInt(editTextPort
.getText().toString()),
Msg);
clientTask.execute();

;
public class ClientTask extends AsyncTask <Void, Void, Void>

String IPaddress;
int portAddress;
String AnswerFromServer ="";
String msgToServer;

ClientTask(String address, int port, String msgToServ)
IPaddress = address;
portAddress = port;
msgToServer = msgToServ;


@Override
protected void onPreExecute()
progressBar.setVisibility(ProgressBar.VISIBLE);


@Override
protected Void doInBackground(Void... arg0)

Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;

try
socket = new Socket(IPaddress,portAddress);

dataOutputStream = new DataOutputStream(
socket.getOutputStream());
BufferedReader br = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
// dataInputStream = new DataInputStream(
// socket.getInputStream());

if(msgToServer != null)
dataOutputStream.writeUTF(msgToServer);


AnswerFromServer = br.readLine();

String password = "123";
String type = "login";
BackgroundWorker backgroundWorker =
new BackgroundWorker(MainActivity.this);
backgroundWorker.execute(type, AnswerFromServer, password);


catch (UnknownHostException e)
e.printStackTrace();
AnswerFromServer = e.toString();
catch (IOException e)
e.printStackTrace();
AnswerFromServer = e.toString();
finally
if(socket != null)
try
socket.close();
catch (IOException e)
e.printStackTrace();




if(dataOutputStream != null)
try
dataOutputStream.close();
catch (IOException e)
e.printStackTrace();



if(dataInputStream != null)
try
dataInputStream.close();
catch (IOException e)
e.printStackTrace();



return null;



@Override
protected void onPostExecute(Void aVoid)
progressBar.setVisibility(ProgressBar.INVISIBLE);
textAnswer.setText(AnswerFromServer);
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG);
super.onPostExecute(aVoid);



public class BackgroundWorker extends AsyncTask<String,Void,String>

Context context;
AlertDialog alertDialog;
BackgroundWorker (Context ctx)




@Override
protected String doInBackground(String... params)
String type = params[0];
String login_url="http;//192.168.8.103/login.php";
if (type.equals("login"))

try

String user_name = params[1];
String password = params[2];
URL url = new URL(login_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter =
new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String post_data =
URLEncoder.encode("user_name","UTF-8")
+"="
+ URLEncoder.encode(user_name,"UTF-8")
+"&"
+URLEncoder.encode("password","UTF-8")+"="+ URLEncoder.encode(password,"UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result="";
String line="";
while ((line=bufferedReader.readLine())!=null)

result+=line;


bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;






catch (MalformedURLException e)

e.printStackTrace();


catch (IOException e)

e.printStackTrace();



return null;


@Override
protected void onPreExecute()
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Login Status");


@Override
protected void onPostExecute(String result)
alertDialog.setMessage(result);
alertDialog.show();














share|improve this question
























  • Debugging on the phone is probably not a good idea. Have you tried running it from an emulator like "Android Virtual Device" from Android Sutdio ?

    – Gabriel Devillers
    Nov 14 '18 at 18:39











  • (By running in an emulator / attaching a debugger, you will be able to know which lines cause the crash, which is very helpful)

    – Gabriel Devillers
    Nov 14 '18 at 18:40











  • I kind of know the problem is in using the AsyncTask twice but I don't know how to correct it

    – Khizrum Ahmed
    Nov 14 '18 at 18:46
















0















I'm getting to receive data from Python server on android client, and i'm storing the data in a variable called Answerfromserver. After that I'm using the Answerfromserver to retrieve data from wamp database. Now when i install the app on my phone, what happens is that when i get the correct data for retrieval from wamp, so my app crashes. I'm attaching my app code, please help me on this..



Edit - I commented out the execute of the code where the data is received from the mysql wamp server, so in that case my app is correctly displaying the data from python server, but i comment out the execute of the python server code app crashes..



package marecki.androidsocketclient;

import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.URLEncoder;
import java.net.UnknownHostException;

import static java.io.DataInputStream.readUTF;

public class MainActivity extends AppCompatActivity

TextView textAnswer;
Button buttonConnect;
EditText editTextIP, editTextPort, message;
ProgressBar progressBar;
String result="";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textAnswer = (TextView)findViewById(R.id.text_answer);
buttonConnect = (Button)findViewById(R.id.connect);
editTextIP = (EditText)findViewById(R.id.address);
editTextPort = (EditText)findViewById(R.id.port);
message = (EditText)findViewById(R.id.edit_message);

progressBar = (ProgressBar)findViewById((R.id.progressBar));
progressBar.setVisibility(ProgressBar.INVISIBLE);

buttonConnect.setOnClickListener(buttonConnectOnClickListener);


OnClickListener buttonConnectOnClickListener = new OnClickListener()

@Override
public void onClick(View arg0)

String Msg = message.getText().toString();

ClientTask clientTask = new ClientTask(
editTextIP.getText().toString(),
Integer.parseInt(editTextPort
.getText().toString()),
Msg);
clientTask.execute();

;
public class ClientTask extends AsyncTask <Void, Void, Void>

String IPaddress;
int portAddress;
String AnswerFromServer ="";
String msgToServer;

ClientTask(String address, int port, String msgToServ)
IPaddress = address;
portAddress = port;
msgToServer = msgToServ;


@Override
protected void onPreExecute()
progressBar.setVisibility(ProgressBar.VISIBLE);


@Override
protected Void doInBackground(Void... arg0)

Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;

try
socket = new Socket(IPaddress,portAddress);

dataOutputStream = new DataOutputStream(
socket.getOutputStream());
BufferedReader br = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
// dataInputStream = new DataInputStream(
// socket.getInputStream());

if(msgToServer != null)
dataOutputStream.writeUTF(msgToServer);


AnswerFromServer = br.readLine();

String password = "123";
String type = "login";
BackgroundWorker backgroundWorker =
new BackgroundWorker(MainActivity.this);
backgroundWorker.execute(type, AnswerFromServer, password);


catch (UnknownHostException e)
e.printStackTrace();
AnswerFromServer = e.toString();
catch (IOException e)
e.printStackTrace();
AnswerFromServer = e.toString();
finally
if(socket != null)
try
socket.close();
catch (IOException e)
e.printStackTrace();




if(dataOutputStream != null)
try
dataOutputStream.close();
catch (IOException e)
e.printStackTrace();



if(dataInputStream != null)
try
dataInputStream.close();
catch (IOException e)
e.printStackTrace();



return null;



@Override
protected void onPostExecute(Void aVoid)
progressBar.setVisibility(ProgressBar.INVISIBLE);
textAnswer.setText(AnswerFromServer);
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG);
super.onPostExecute(aVoid);



public class BackgroundWorker extends AsyncTask<String,Void,String>

Context context;
AlertDialog alertDialog;
BackgroundWorker (Context ctx)




@Override
protected String doInBackground(String... params)
String type = params[0];
String login_url="http;//192.168.8.103/login.php";
if (type.equals("login"))

try

String user_name = params[1];
String password = params[2];
URL url = new URL(login_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter =
new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String post_data =
URLEncoder.encode("user_name","UTF-8")
+"="
+ URLEncoder.encode(user_name,"UTF-8")
+"&"
+URLEncoder.encode("password","UTF-8")+"="+ URLEncoder.encode(password,"UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result="";
String line="";
while ((line=bufferedReader.readLine())!=null)

result+=line;


bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;






catch (MalformedURLException e)

e.printStackTrace();


catch (IOException e)

e.printStackTrace();



return null;


@Override
protected void onPreExecute()
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Login Status");


@Override
protected void onPostExecute(String result)
alertDialog.setMessage(result);
alertDialog.show();














share|improve this question
























  • Debugging on the phone is probably not a good idea. Have you tried running it from an emulator like "Android Virtual Device" from Android Sutdio ?

    – Gabriel Devillers
    Nov 14 '18 at 18:39











  • (By running in an emulator / attaching a debugger, you will be able to know which lines cause the crash, which is very helpful)

    – Gabriel Devillers
    Nov 14 '18 at 18:40











  • I kind of know the problem is in using the AsyncTask twice but I don't know how to correct it

    – Khizrum Ahmed
    Nov 14 '18 at 18:46














0












0








0








I'm getting to receive data from Python server on android client, and i'm storing the data in a variable called Answerfromserver. After that I'm using the Answerfromserver to retrieve data from wamp database. Now when i install the app on my phone, what happens is that when i get the correct data for retrieval from wamp, so my app crashes. I'm attaching my app code, please help me on this..



Edit - I commented out the execute of the code where the data is received from the mysql wamp server, so in that case my app is correctly displaying the data from python server, but i comment out the execute of the python server code app crashes..



package marecki.androidsocketclient;

import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.URLEncoder;
import java.net.UnknownHostException;

import static java.io.DataInputStream.readUTF;

public class MainActivity extends AppCompatActivity

TextView textAnswer;
Button buttonConnect;
EditText editTextIP, editTextPort, message;
ProgressBar progressBar;
String result="";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textAnswer = (TextView)findViewById(R.id.text_answer);
buttonConnect = (Button)findViewById(R.id.connect);
editTextIP = (EditText)findViewById(R.id.address);
editTextPort = (EditText)findViewById(R.id.port);
message = (EditText)findViewById(R.id.edit_message);

progressBar = (ProgressBar)findViewById((R.id.progressBar));
progressBar.setVisibility(ProgressBar.INVISIBLE);

buttonConnect.setOnClickListener(buttonConnectOnClickListener);


OnClickListener buttonConnectOnClickListener = new OnClickListener()

@Override
public void onClick(View arg0)

String Msg = message.getText().toString();

ClientTask clientTask = new ClientTask(
editTextIP.getText().toString(),
Integer.parseInt(editTextPort
.getText().toString()),
Msg);
clientTask.execute();

;
public class ClientTask extends AsyncTask <Void, Void, Void>

String IPaddress;
int portAddress;
String AnswerFromServer ="";
String msgToServer;

ClientTask(String address, int port, String msgToServ)
IPaddress = address;
portAddress = port;
msgToServer = msgToServ;


@Override
protected void onPreExecute()
progressBar.setVisibility(ProgressBar.VISIBLE);


@Override
protected Void doInBackground(Void... arg0)

Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;

try
socket = new Socket(IPaddress,portAddress);

dataOutputStream = new DataOutputStream(
socket.getOutputStream());
BufferedReader br = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
// dataInputStream = new DataInputStream(
// socket.getInputStream());

if(msgToServer != null)
dataOutputStream.writeUTF(msgToServer);


AnswerFromServer = br.readLine();

String password = "123";
String type = "login";
BackgroundWorker backgroundWorker =
new BackgroundWorker(MainActivity.this);
backgroundWorker.execute(type, AnswerFromServer, password);


catch (UnknownHostException e)
e.printStackTrace();
AnswerFromServer = e.toString();
catch (IOException e)
e.printStackTrace();
AnswerFromServer = e.toString();
finally
if(socket != null)
try
socket.close();
catch (IOException e)
e.printStackTrace();




if(dataOutputStream != null)
try
dataOutputStream.close();
catch (IOException e)
e.printStackTrace();



if(dataInputStream != null)
try
dataInputStream.close();
catch (IOException e)
e.printStackTrace();



return null;



@Override
protected void onPostExecute(Void aVoid)
progressBar.setVisibility(ProgressBar.INVISIBLE);
textAnswer.setText(AnswerFromServer);
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG);
super.onPostExecute(aVoid);



public class BackgroundWorker extends AsyncTask<String,Void,String>

Context context;
AlertDialog alertDialog;
BackgroundWorker (Context ctx)




@Override
protected String doInBackground(String... params)
String type = params[0];
String login_url="http;//192.168.8.103/login.php";
if (type.equals("login"))

try

String user_name = params[1];
String password = params[2];
URL url = new URL(login_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter =
new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String post_data =
URLEncoder.encode("user_name","UTF-8")
+"="
+ URLEncoder.encode(user_name,"UTF-8")
+"&"
+URLEncoder.encode("password","UTF-8")+"="+ URLEncoder.encode(password,"UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result="";
String line="";
while ((line=bufferedReader.readLine())!=null)

result+=line;


bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;






catch (MalformedURLException e)

e.printStackTrace();


catch (IOException e)

e.printStackTrace();



return null;


@Override
protected void onPreExecute()
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Login Status");


@Override
protected void onPostExecute(String result)
alertDialog.setMessage(result);
alertDialog.show();














share|improve this question
















I'm getting to receive data from Python server on android client, and i'm storing the data in a variable called Answerfromserver. After that I'm using the Answerfromserver to retrieve data from wamp database. Now when i install the app on my phone, what happens is that when i get the correct data for retrieval from wamp, so my app crashes. I'm attaching my app code, please help me on this..



Edit - I commented out the execute of the code where the data is received from the mysql wamp server, so in that case my app is correctly displaying the data from python server, but i comment out the execute of the python server code app crashes..



package marecki.androidsocketclient;

import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.net.URLEncoder;
import java.net.UnknownHostException;

import static java.io.DataInputStream.readUTF;

public class MainActivity extends AppCompatActivity

TextView textAnswer;
Button buttonConnect;
EditText editTextIP, editTextPort, message;
ProgressBar progressBar;
String result="";

@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textAnswer = (TextView)findViewById(R.id.text_answer);
buttonConnect = (Button)findViewById(R.id.connect);
editTextIP = (EditText)findViewById(R.id.address);
editTextPort = (EditText)findViewById(R.id.port);
message = (EditText)findViewById(R.id.edit_message);

progressBar = (ProgressBar)findViewById((R.id.progressBar));
progressBar.setVisibility(ProgressBar.INVISIBLE);

buttonConnect.setOnClickListener(buttonConnectOnClickListener);


OnClickListener buttonConnectOnClickListener = new OnClickListener()

@Override
public void onClick(View arg0)

String Msg = message.getText().toString();

ClientTask clientTask = new ClientTask(
editTextIP.getText().toString(),
Integer.parseInt(editTextPort
.getText().toString()),
Msg);
clientTask.execute();

;
public class ClientTask extends AsyncTask <Void, Void, Void>

String IPaddress;
int portAddress;
String AnswerFromServer ="";
String msgToServer;

ClientTask(String address, int port, String msgToServ)
IPaddress = address;
portAddress = port;
msgToServer = msgToServ;


@Override
protected void onPreExecute()
progressBar.setVisibility(ProgressBar.VISIBLE);


@Override
protected Void doInBackground(Void... arg0)

Socket socket = null;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = null;

try
socket = new Socket(IPaddress,portAddress);

dataOutputStream = new DataOutputStream(
socket.getOutputStream());
BufferedReader br = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
// dataInputStream = new DataInputStream(
// socket.getInputStream());

if(msgToServer != null)
dataOutputStream.writeUTF(msgToServer);


AnswerFromServer = br.readLine();

String password = "123";
String type = "login";
BackgroundWorker backgroundWorker =
new BackgroundWorker(MainActivity.this);
backgroundWorker.execute(type, AnswerFromServer, password);


catch (UnknownHostException e)
e.printStackTrace();
AnswerFromServer = e.toString();
catch (IOException e)
e.printStackTrace();
AnswerFromServer = e.toString();
finally
if(socket != null)
try
socket.close();
catch (IOException e)
e.printStackTrace();




if(dataOutputStream != null)
try
dataOutputStream.close();
catch (IOException e)
e.printStackTrace();



if(dataInputStream != null)
try
dataInputStream.close();
catch (IOException e)
e.printStackTrace();



return null;



@Override
protected void onPostExecute(Void aVoid)
progressBar.setVisibility(ProgressBar.INVISIBLE);
textAnswer.setText(AnswerFromServer);
Toast.makeText(MainActivity.this,result,Toast.LENGTH_LONG);
super.onPostExecute(aVoid);



public class BackgroundWorker extends AsyncTask<String,Void,String>

Context context;
AlertDialog alertDialog;
BackgroundWorker (Context ctx)




@Override
protected String doInBackground(String... params)
String type = params[0];
String login_url="http;//192.168.8.103/login.php";
if (type.equals("login"))

try

String user_name = params[1];
String password = params[2];
URL url = new URL(login_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter =
new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String post_data =
URLEncoder.encode("user_name","UTF-8")
+"="
+ URLEncoder.encode(user_name,"UTF-8")
+"&"
+URLEncoder.encode("password","UTF-8")+"="+ URLEncoder.encode(password,"UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader =
new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
String result="";
String line="";
while ((line=bufferedReader.readLine())!=null)

result+=line;


bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;






catch (MalformedURLException e)

e.printStackTrace();


catch (IOException e)

e.printStackTrace();



return null;


@Override
protected void onPreExecute()
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Login Status");


@Override
protected void onPostExecute(String result)
alertDialog.setMessage(result);
alertDialog.show();











java android python mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 20:00







Khizrum Ahmed

















asked Nov 14 '18 at 18:34









Khizrum AhmedKhizrum Ahmed

12




12












  • Debugging on the phone is probably not a good idea. Have you tried running it from an emulator like "Android Virtual Device" from Android Sutdio ?

    – Gabriel Devillers
    Nov 14 '18 at 18:39











  • (By running in an emulator / attaching a debugger, you will be able to know which lines cause the crash, which is very helpful)

    – Gabriel Devillers
    Nov 14 '18 at 18:40











  • I kind of know the problem is in using the AsyncTask twice but I don't know how to correct it

    – Khizrum Ahmed
    Nov 14 '18 at 18:46


















  • Debugging on the phone is probably not a good idea. Have you tried running it from an emulator like "Android Virtual Device" from Android Sutdio ?

    – Gabriel Devillers
    Nov 14 '18 at 18:39











  • (By running in an emulator / attaching a debugger, you will be able to know which lines cause the crash, which is very helpful)

    – Gabriel Devillers
    Nov 14 '18 at 18:40











  • I kind of know the problem is in using the AsyncTask twice but I don't know how to correct it

    – Khizrum Ahmed
    Nov 14 '18 at 18:46

















Debugging on the phone is probably not a good idea. Have you tried running it from an emulator like "Android Virtual Device" from Android Sutdio ?

– Gabriel Devillers
Nov 14 '18 at 18:39





Debugging on the phone is probably not a good idea. Have you tried running it from an emulator like "Android Virtual Device" from Android Sutdio ?

– Gabriel Devillers
Nov 14 '18 at 18:39













(By running in an emulator / attaching a debugger, you will be able to know which lines cause the crash, which is very helpful)

– Gabriel Devillers
Nov 14 '18 at 18:40





(By running in an emulator / attaching a debugger, you will be able to know which lines cause the crash, which is very helpful)

– Gabriel Devillers
Nov 14 '18 at 18:40













I kind of know the problem is in using the AsyncTask twice but I don't know how to correct it

– Khizrum Ahmed
Nov 14 '18 at 18:46






I kind of know the problem is in using the AsyncTask twice but I don't know how to correct it

– Khizrum Ahmed
Nov 14 '18 at 18:46













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306717%2freceiving-value-from-python-server-on-android-app-client-and-then-displaying-dat%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306717%2freceiving-value-from-python-server-on-android-app-client-and-then-displaying-dat%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Darth Vader #20

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Ondo