Prashant Sontale
Newbie
I have a android app that takes the values from user for student, such as FirstName, LastName and Class. When the user inputs the values and clicks on button, it calls the API and stores the values into database.
I am using Yii framework and REST API. Here when I run, there is error as com.android.volley.ServerError.
But the values get stored in the database. Following is the code.
What should I do? I test it using Postman, there also the values are getting saved in table but the response is not working as needed.
I am using Yii framework and REST API. Here when I run, there is error as com.android.volley.ServerError.
But the values get stored in the database. Following is the code.
What should I do? I test it using Postman, there also the values are getting saved in table but the response is not working as needed.
Code:
package com.example.anitaa.studentadd;
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.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 MainActivity extends AppCompatActivity {
EditText FirstName, LastName, Class;
Button button;
String url1="http://192.168.1.3/student/web/studentrecords";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity_main );
FirstName= (EditText) findViewById(R.id.firstname);
LastName= (EditText) findViewById(R.id.lastname);
Class= (EditText) findViewById(R.id.studentclass);
button = (Button) findViewById(R.id.studentinformation);
button.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View v) {
final String fname,lname,class2;
fname = FirstName.getText().toString();
lname = LastName.getText().toString();
class2 = Class.getText().toString();
StringRequest stringRequest1 = new StringRequest ( Request.Method.POST, url1, new Response.Listener<String> () {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this,response.toString (),Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener () {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.toString (),Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
} ){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String> ();
params.put("FirstName",fname);
params.put("LastName",lname);
params.put("Class",class2);
return params;
}
};
MySingleton.getInstance ( MainActivity.this ).addToRequestque ( stringRequest1 );
}
} );
}
}