----------------Here is my code for android login with php mysql xampp-----------------
-----LoginActivity----
package com.myapp.ravisingham.loginapp;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.iutputStream;
import java.iutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
public class LoginActivity extends AppCompatActivity {
EditText username,password;
String uname,pwd;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
}
public void invokeLogin(View view){
uname = username.getText().toString();
pwd = password.getText().toString();
login(uname, pwd);
}
public void login(final String uname, String pwd) {
class loginAsync extends AsyncTask<String, Void, String> {
private Dialog loadDialogue;
@override
protected void onPreExecute() {
super.onPreExecute();
loadDialogue = ProgressDialog.show(LoginActivity.this, "Please wait...", "Loading");
}
@override
protected String doInBackground(String... params) {
JSONObject jsonObject;
String result="";
try {
URL url = new URL("https://localhost/Android App/Login.php");
jsonObject = new JSONObject();
jsonObject.put("uname", params[0]);
jsonObject.put("pwd", params[1]);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setReadTimeout(15000);
httpURLConnection.setConnectTimeout(15000);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
writer.write(getPostDataString(jsonObject));
writer.flush();
writer.close();
outputStream.close();
int responsecode = httpURLConnection.getResponseCode();
if (responsecode == HttpURLConnection.HTTP_OK) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuilder sb = new StringBuilder(" ");
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
bufferedReader.close();
result = sb.toString();
}
else {
return new String("false " + responsecode);
}
}
catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
@override
protected void onPostExecute(String result) {
String s = result.trim();
loadDialogue.dismiss();
if(s.equalsIgnoreCase("success")){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
finish();
startActivity(intent);
}else {
Toast.makeText(getApplicationContext(), "Invalid User Name or Password", Toast.LENGTH_LONG).show();
}
}
}
}
public String getPostDataString(JSONObject params) throws Exception {
StringBuilder result = new StringBuilder();
boolean first = true;
Iterator<String> itr = params.keys();
while (itr.hasNext()) {
String key = itr.next();
Object value = params.get(key);
if (first)
first = false;
else {
result.append("&");
result.append(URLEncoder.encode(key, "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(value.toString(), "UTF-8"));
}
}
return result.toString();
}
}
--------Error----------------
Executing tasks: [:app:assembleDebug]
Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:appreBuild UP-TO-DATE
:appreDebugBuild UP-TO-DATE
:app:checkDebugManifest
:appreReleaseBuild UP-TO-DATE
:apprepareComAndroidSupportAnimatedVectorDrawable2511Library
:apprepareComAndroidSupportAppcompatV72511Library
:apprepareComAndroidSupportSupportCompat2511Library
:apprepareComAndroidSupportSupportCoreUi2511Library
:apprepareComAndroidSupportSupportCoreUtils2511Library
:apprepareComAndroidSupportSupportFragment2511Library
:apprepareComAndroidSupportSupportMediaCompat2511Library
:apprepareComAndroidSupportSupportV42511Library
:apprepareComAndroidSupportSupportVectorDrawable2511Library
:apprepareComGoogleAndroidGmsPlayServicesAppindexing840Library
:apprepareComGoogleAndroidGmsPlayServicesBase840Library
:apprepareComGoogleAndroidGmsPlayServicesBasement840Library
:apprepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript FAILED
FAILURE: Build failed with an exception.
* What went wrong:
null value in entry: libOutputDir=null
-----LoginActivity----
package com.myapp.ravisingham.loginapp;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.iutputStream;
import java.iutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
public class LoginActivity extends AppCompatActivity {
EditText username,password;
String uname,pwd;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
}
public void invokeLogin(View view){
uname = username.getText().toString();
pwd = password.getText().toString();
login(uname, pwd);
}
public void login(final String uname, String pwd) {
class loginAsync extends AsyncTask<String, Void, String> {
private Dialog loadDialogue;
@override
protected void onPreExecute() {
super.onPreExecute();
loadDialogue = ProgressDialog.show(LoginActivity.this, "Please wait...", "Loading");
}
@override
protected String doInBackground(String... params) {
JSONObject jsonObject;
String result="";
try {
URL url = new URL("https://localhost/Android App/Login.php");
jsonObject = new JSONObject();
jsonObject.put("uname", params[0]);
jsonObject.put("pwd", params[1]);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setReadTimeout(15000);
httpURLConnection.setConnectTimeout(15000);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
writer.write(getPostDataString(jsonObject));
writer.flush();
writer.close();
outputStream.close();
int responsecode = httpURLConnection.getResponseCode();
if (responsecode == HttpURLConnection.HTTP_OK) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuilder sb = new StringBuilder(" ");
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
bufferedReader.close();
result = sb.toString();
}
else {
return new String("false " + responsecode);
}
}
catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
@override
protected void onPostExecute(String result) {
String s = result.trim();
loadDialogue.dismiss();
if(s.equalsIgnoreCase("success")){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
finish();
startActivity(intent);
}else {
Toast.makeText(getApplicationContext(), "Invalid User Name or Password", Toast.LENGTH_LONG).show();
}
}
}
}
public String getPostDataString(JSONObject params) throws Exception {
StringBuilder result = new StringBuilder();
boolean first = true;
Iterator<String> itr = params.keys();
while (itr.hasNext()) {
String key = itr.next();
Object value = params.get(key);
if (first)
first = false;
else {
result.append("&");
result.append(URLEncoder.encode(key, "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(value.toString(), "UTF-8"));
}
}
return result.toString();
}
}
--------Error----------------
Executing tasks: [:app:assembleDebug]
Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:appreBuild UP-TO-DATE
:appreDebugBuild UP-TO-DATE
:app:checkDebugManifest
:appreReleaseBuild UP-TO-DATE
:apprepareComAndroidSupportAnimatedVectorDrawable2511Library
:apprepareComAndroidSupportAppcompatV72511Library
:apprepareComAndroidSupportSupportCompat2511Library
:apprepareComAndroidSupportSupportCoreUi2511Library
:apprepareComAndroidSupportSupportCoreUtils2511Library
:apprepareComAndroidSupportSupportFragment2511Library
:apprepareComAndroidSupportSupportMediaCompat2511Library
:apprepareComAndroidSupportSupportV42511Library
:apprepareComAndroidSupportSupportVectorDrawable2511Library
:apprepareComGoogleAndroidGmsPlayServicesAppindexing840Library
:apprepareComGoogleAndroidGmsPlayServicesBase840Library
:apprepareComGoogleAndroidGmsPlayServicesBasement840Library
:apprepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript FAILED
FAILURE: Build failed with an exception.
* What went wrong:
null value in entry: libOutputDir=null