0

please guys i need ur help!.. I am new to Volley and i have been trying to do the login and registeration using volley. To say Insertion and retrieval. The problem is i cannot retrieve o insert anything i the db im using json array and json object. Please help me. My files are here below.

MainActivity
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    Button login_button;
    EditText Username,Password;
    String username,password;
    String login_url = "http://IP_ADDRS/VolleyAndroid/login.php";
    AlertDialog.Builder builder;

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

        builder = new AlertDialog.Builder(MainActivity.this);
        login_button = (Button)findViewById(R.id.login_btn);
        Username = (EditText)findViewById(R.id.emailln);
        Password = (EditText)findViewById(R.id.passln);
        login_button.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v){
                username = Username.getText().toString();
                password = Password.getText().toString();

                if(username.equals("") || password.equals("")){
                    builder.setTitle("Something Went wrong");
                    displayAlert("Enter a valid username and password");
                }
                else{
                    StringRequest stringRequest = new StringRequest(Request.Method.POST, login_url,
                    new Response.Listener<String>(){
                        @Override
                        public void onResponse(String response){

                            try {
                                JSONArray jsonArray = new JSONArray(response);
                                JSONObject jsonObject = jsonArray.getJSONObject(0);
                                String code = jsonObject.getString("code");
                                if(code.equals("login_failed")){
                                    builder.setTitle("Login Error");
                                    displayAlert(jsonObject.getString("message"));
                                }
                                else{
                                    Intent intent = new Intent (MainActivity.this,LoginSuccess.class);
                                    Bundle bundle = new Bundle();
                                    bundle.putString("name",jsonObject.getString("name"));
                                    bundle.putString("email",jsonObject.getString("email"));
                                    intent.putExtras(bundle);
                                    startActivity(intent);

                                }

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    }, new Response.ErrorListener(){
                        @Override
                        public void onErrorResponse(VolleyError error){

                        }

                    })
                    {
                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {
                        Map<String,String> params = new HashMap<String, String>();
                        params.put("user_name",username);
                        params.put("password",password);
                        return params;
                    }
                    };
                    MySingleton.getInstance(MainActivity.this).addToRequest(stringRequest);
                }
            }
        });

    }

    public void displayAlert(String message){
        builder.setMessage(message);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Username.setText("");
                Password.setText("");
            }
        });

        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }

    public void register(View v){
        Intent intent = new Intent(getApplicationContext(),Register.class);
        startActivity(intent);
    }
}

Register
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class Register extends AppCompatActivity {
    Button reg_bn;
    EditText Name,Phone,Email,Password,ConPassword;
    String name,phone,email,password,conpass;
    AlertDialog.Builder builder;

    String reg_url = "http://IP_ADDRS/VolleyAndroid/register.php";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        reg_bn = (Button)findViewById(R.id.registerbtn);
        Name = (EditText)findViewById(R.id.nameedit);
        Phone = (EditText)findViewById(R.id.phoneedit);
        Email = (EditText)findViewById(R.id.emailedit);
        Password = (EditText)findViewById(R.id.passedit);
        ConPassword = (EditText)findViewById(R.id.cpassedit);
        builder = new AlertDialog.Builder(Register.this);
        reg_bn.setOnClickListener(new View.OnClickListener(){

            public void onClick(View v)
            {
                name = Name.getText().toString();
                phone = Phone.getText().toString();
                email = Email.getText().toString();
                password = Password.getText().toString();
                conpass = ConPassword.getText().toString();

                if(name.equals("") || phone.equals("") || email.equals("") || password.equals("") || conpass.equals("")){
                    builder.setTitle("Something went Wrng!!");
                    builder.setMessage("Please enter all the feilds");
                    displayAlert("input_err");
                }

                else{
                    if(!(password.equals(conpass))){
                        builder.setTitle("Something went wrong!!");
                        builder.setMessage("Password incorrect!");
                        displayAlert("input_err");
                    }
                    else{
                        StringRequest stringRequest = new StringRequest(Request.Method.POST, reg_url,
                                new Response.Listener<String>() {
                                    @Override
                                    public void onResponse(String response) {
                                        try {
                                            JSONArray jsonArray = new JSONArray(response);
                                            JSONObject jsonObject = jsonArray.getJSONObject(0);
                                            String code = jsonObject.getString("code");
                                            String message = jsonObject.getString("message");
                                            builder.setTitle("Response from server");
                                            builder.setMessage(message);
                                            displayAlert(code);
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }

                                    }
                                }, new Response.ErrorListener(){
                            public void onErrorResponse(VolleyError error){

                            }
                        }){
                          @Override
                            protected Map<String, String> getParams() throws AuthFailureError{
                              Map<String, String> params =new HashMap<String, String>();
                              params.put("name",name);
                              params.put("phone",phone);
                              params.put("email",email);
                              params.put("pass",password);


                              return params;
                          }
                        };

                        MySingleton.getInstance(Register.this).addToRequest(stringRequest);
                    }
                }
            }
        });
    }

    public void displayAlert(final String code){
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if(code.equals("input_error"))
                {
                    Password.setText("");
                    ConPassword.setText("");
                }
                else if(code.equals("reg_success"))
                {
                 finish();
                }
                else if(code.equals("reg_failed")){
                    Name.setText("");
                    Phone.setText("");
                    Email.setText("");
                    Password.setText("");
                    ConPassword.setText("");
                }
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}

MySingleton
import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

/**
 * Created by sshank on 5/1/17.
 */

public class MySingleton {
    private static MySingleton mInstance;
    private RequestQueue requestQueue;
    private static Context mctx;
    private MySingleton(Context context){
        mctx = context;
        requestQueue = getRequestQueue();
    }

    private RequestQueue getRequestQueue() {
        if(requestQueue == null)
        {
            requestQueue = Volley.newRequestQueue(mctx.getApplicationContext());

        }
        return requestQueue;
    }

    public static synchronized MySingleton getInstance(Context context)
    {
        if(mInstance == null)
        {
            mInstance = new MySingleton(context);
        }
        return mInstance;
    }

    public <T>void addToRequest(Request<T> request)
    {
        requestQueue.add(request);
    }
}

My layout files
activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.company.sshank.volleyimplementation.MainActivity">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Easy Travel Connect"
        android:textAlignment="center"
        android:textSize="25dp"
        android:layout_marginTop="35dp"
        />
    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/block1"
        android:layout_below="@+id/title"
        android:layout_marginTop="50dp">
    <TextView
        android:id="@+id/emailtxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Email"></TextView>

    <EditText
        android:id="@+id/emailln"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_below="@+id/emailtxt"></EditText>

    <TextView
        android:id="@+id/passtxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Password"
        android:layout_below="@+id/emailln"></TextView>

    <EditText
        android:id="@+id/passln"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_below="@+id/passtxt"></EditText>

        <Button
            android:id="@+id/login_btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/passln"
            android:layout_marginTop="25dp"
            android:text="Sign In"></Button>
        </RelativeLayout>

    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/block2"
        android:layout_below="@+id/block1">

        <TextView android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/registerlink"
            android:text="Not a user? Connect now!"
            android:onClick="register"
            android:gravity="center"
            android:layout_marginTop="10dp"/>

        <TextView android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/terms"
            android:layout_below="@+id/registerlink"
            android:text="I Agree to the terms and conditions"
            android:layout_marginTop="120dp"
            android:textStyle="bold"
            android:gravity="center" />
    </RelativeLayout>
</RelativeLayout>

activity_register
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_register"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.company.sshank.volleyimplementation.Register">


    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Easy Travel Connect"
        android:textAlignment="center"
        android:textSize="25dp"
        android:layout_marginTop="25dp"
        />
    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/block1"
        android:layout_below="@+id/title"
        android:layout_marginTop="30dp">

        <TextView
            android:id="@+id/nametxt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Name"></TextView>

        <EditText
            android:id="@+id/nameedit"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_below="@+id/nametxt"></EditText>

        <TextView
            android:id="@+id/phonetxt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Phone"
            android:layout_below="@+id/nameedit"></TextView>

        <EditText
            android:id="@+id/phoneedit"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_below="@+id/phonetxt"></EditText>

        <TextView
            android:id="@+id/emailtxt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Email"
            android:layout_below="@+id/phoneedit"></TextView>

        <EditText
            android:id="@+id/emailedit"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_below="@+id/emailtxt"></EditText>

        <TextView
            android:id="@+id/passtxt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Password"
            android:layout_below="@+id/emailedit"></TextView>

        <EditText
            android:id="@+id/passedit"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_below="@+id/passtxt"></EditText>

        <TextView
            android:id="@+id/cpasstxt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Confirm Password"
            android:layout_below="@+id/passedit"></TextView>

        <EditText
            android:id="@+id/cpassedit"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_below="@+id/cpasstxt"></EditText>

        <Button
            android:id="@+id/registerbtn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/cpassedit"
            android:layout_marginTop="15dp"
            android:text="Register"></Button>
    </RelativeLayout>

    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/block2"
        android:layout_below="@+id/block1">

           <TextView android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:id="@+id/terms"
            android:layout_below="@+id/registerlink"
            android:text="I Agree to the terms and conditions"
            android:layout_marginTop="10dp"
            android:textStyle="bold"
            android:gravity="center" />
    </RelativeLayout>


</RelativeLayout>

Php files.. here im retrieving and inserting data
login
<?php
$host = "localhost";
$user = "username";
$pass = "";
$db = "db_name";
$conn = mysqli_connect($host, $user, $pass, $db);


    $email = $_POST['email'];
$password = $_POST['password'];


$query = "select * from Login where email like '".$email."'and password like '".$password."';";
$result = mysqli_query($conn, $query);
$response = array();

if(mysqli_num_rows($result)>0)
{
    $row = mysqli_fetch_row($result);
    $name = $row[0];
    $phone = $row[1];
    $code = "login_success";
    array_push($response, array("code"=>$code,"name"=>$name,"phone"=>$phone));
    echo json_encode($response);
}else{
$code = "login_failed";
    $message = "User not found...Please try again...";
    array_push($response, array("code"=>$code,"message"=>$message));
    echo json_encode($response);
}


mysqli_close($conn);
?>

Register
<?php
$host = "localhost";
$user = "username";
$pass = "";
$db = "dbname";

$conn = mysqli_connect($host, $user, $pass, $db);

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$password = $_POST['password'];


$query = "select * from Login where email like '".$email."';";
$result = mysqli_query($conn, $query);
$response = array();

if(mysqli_num_rows($result)>0)
{
    $code = "reg_failed";
    $message = "User exist";
    array_push($response, array("code"=>$code,"message"=>$message));
    echo json_encode($response);
}else{
    $query = "insert into Login (name,phone,email,password) 
            values ('".$name."', '".$phone."', '".$email."', '".$password."')";
$result = mysqli_query($conn, $query);
$code = "reg_success";
    $message = "Thank you for rgistering with us!! Now you can login!";
    array_push($response, array("code"=>$code,"message"=>$message));
    echo json_encode($response);
}

?>
Sshank
  • 13
  • 5
  • Place debugger in `onErrorResponse` and see what's the error you are getting? – Guruprasad J Rao Jan 09 '17 at 10:19
  • com.android.volley.TimeoutError @GuruprasadRao – Sshank Jan 09 '17 at 11:58
  • That means your application is not able to connect to the server within the specified amount of time. First make sure your server is accessible. Next try setting `setRetryPolicy` option for your requests. Here is the **[reference post](http://stackoverflow.com/questions/17094718/change-volley-timeout-duration)** for the said option. – Guruprasad J Rao Jan 09 '17 at 12:23
  • your Singleton class has error try my code of that class and try to add request and tell – W4R10CK Jan 09 '17 at 12:37
  • Can you tel me the error? @W4R10CK cz i tried ur class too.. no success. Can you help me figure out only with connection part to the php?.. cz everythn is fine. jus the jsonArray and stuf arent working.. Please i need help!! – Sshank Jan 09 '17 at 19:03

3 Answers3

0

Its a broad answer. Certainly Its an example to show how to achieve(It is an example to show and does not contains exact answer asked by user).Try Networking Lib.("Volley") for calls. I example for Login and Registration.

//Layout of Activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
tools:context="com.test.test.ScreenOne">


<EditText
    android:layout_width="240dp"
    android:layout_height="wrap_content"
    android:id="@+id/etUsername"
    android:layout_marginTop="150dp"
    android:hint="username"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<EditText
    android:layout_width="240dp"
    android:layout_height="wrap_content"
    android:id="@+id/etPassword"
    android:hint="password"
    android:layout_below="@+id/etUsername"
    android:layout_centerHorizontal="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Login"
    android:id="@+id/bLogin"
    android:layout_below="@+id/etPassword"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="50dp" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Save"
    android:id="@+id/bSave"
    android:layout_below="@+id/bLogin"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="42dp" />
</RelativeLayout> 

Activity has 2 buttons and 2 EditText, Login button login via server and Save button saves your data in server:

package com.test.test;

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

public class ScreenOne extends AppCompatActivity {

private static final String URL_LOGIN = "http://IP_ADDRESS/login.php";
private static final String URL_SAVE = "http://IP_ADDRESS/save.php";
private EditText username;
private EditText password;
private Button login;
Button save;
String name;
String pass;

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

    username = (EditText) findViewById(R.id.etUsername);
    password = (EditText) findViewById(R.id.etPassword);

    (login = (Button) findViewById(R.id.bLogin)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            request();
        }
    });

    (save = (Button) findViewById(R.id.bSave)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            saveRequest();
        }
    });
}

private void saveRequest() {
    name = username.getText().toString().trim();
    pass = password.getText().toString().trim();
    final ProgressDialog mDialog = new ProgressDialog(this);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setMessage("Loading...");
    mDialog.show();

    StringRequest request = new StringRequest(Request.Method.POST, URL_SAVE,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    mDialog.dismiss();
                    Toast.makeText(ScreenOne.this, response, Toast.LENGTH_LONG).show();
                    username.setText("");
                    password.setText("");
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mDialog.dismiss();
                    Toast.makeText(ScreenOne.this, "Something went wrong", Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> key = new HashMap<>();
            key.put("username", name);
            key.put("password", pass);
            return key;
        }
    };

    NetworkCalls.getInstance().addToRequestQueue(request);
}

private synchronized void request() {
    name = username.getText().toString().trim();
    pass = password.getText().toString().trim();
    final ProgressDialog mDialog = new ProgressDialog(this);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.setMessage("Loading...");
    mDialog.show();

    StringRequest request = new StringRequest(Request.Method.POST, URL_LOGIN,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    mDialog.dismiss();
                    Toast.makeText(ScreenOne.this, response, Toast.LENGTH_LONG).show();
                    username.setText("");
                    password.setText("");
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mDialog.dismiss();
                    Toast.makeText(ScreenOne.this, "Something went wrong", Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> key = new HashMap<>();
            key.put("username", name);
            key.put("password", pass);
            return key;
        }
    };

    NetworkCalls.getInstance().addToRequestQueue(request);
 }
}

Singleton class for Volley request:

import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

/**
 * Created by W4R10CK on 12-09-2016.
 */
public class NetworkCalls {
    private RequestQueue requestQueue;
    private static Context context;

    private static NetworkCalls ourInstance = new NetworkCalls();

    public static NetworkCalls getInstance() {
        return ourInstance;
    }

    private NetworkCalls() {
    }

    public RequestQueue getRequestQueue(){
        requestQueue = Volley.newRequestQueue(context.getApplicationContext());
        return requestQueue;
    }

    public <T> void addToRequestQueue(Request<T> request){
        getRequestQueue().add(request);
    }
}

API to call server:

 //conn.php for connection (file one)
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db_name = "hello";

$con = new mysqli($host,$user,$pass,$db_name);

if($con -> connect_error){
echo "Connection error";
}   


//save.php(file two)
<?php
$username = $_POST['username'];
$password = $_POST['password'];
require_once('conn.php');

$sql = "INSERT INTO user (username, password) VALUES ('$username','$password')";

if($con -> query($sql) === TRUE) {
echo "User added";
}
//$con -> close();
?>
?>

//login.php(file three)
<?php
require_once('conn.php');

$username = $_POST['username'];
$password = $_POST['password'];

$sql = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";

$result = mysqli_query($con,$sql);

if(mysqli_fetch_array($result) == NULL){
echo "Invalid Cred.";
}else{
echo "Success";
}

$con->close();
?>

Lastly create one DB named hello and table in localhost user with 2 fields username, password.

Try to learn more on this link here

W4R10CK
  • 5,502
  • 2
  • 19
  • 30
  • No success @W4R10CK the app is crashing – Sshank Jan 09 '17 at 11:45
  • java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference – Sshank Jan 09 '17 at 12:20
  • com.company.sshank.test.NetworkCalls.getRequestQueue(NetworkCalls.java:26) at com.company.sshank.test.NetworkCalls.addToRequestQueue(NetworkCalls.java:31)at com.company.sshank.test.MainActivity.saveRequest(MainActivity.java:89)at com.company.sshank.test.MainActivity.access$100(MainActivity.java:21) at com.company.sshank.test.MainActivity$2.onClick(MainActivity.java:50) – Sshank Jan 09 '17 at 12:23
  • try the link that i provided for volley, bcoz its working on my side completly, also put proper server url – W4R10CK Jan 09 '17 at 12:30
0

You first have to check your webservice in Postman.

If its working fine and giving proper response then there is no issue in your webservice. . Otherwise, there may be some issue in your backend coading.

As per your ui.. at front end you are using Volly, As per my check there is not an issue in your code since you have used StringObject for Volly parsing.

You can also do it with JsonObjectRequest or JsonArrayRequest if you know that your response contains JsonObject or JsonArray.

ZaptechDev Kumar
  • 164
  • 1
  • 14
0
  1. create API using php to check the json object/array being parsed accross the android app. Test using Postman.
  2. The main problem with your application is that it cant access the json files. So kindly test the PHP json files.