i am new in android. i am making an application in which i am getting the data from server using volley library. but i dont know how to fetch data from server when we use id or parameters. please help.
public class MainActivity extends AppCompatActivity {
Button btn_next,btn_search,cross;
TextView title;
EditText et;
private ProgressDialog pDialog;
public static final String JSON_URL = "http://bcshymns.com/heading.php";
private Button buttonGet;
private ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cross=(Button)findViewById(R.id.cross);
et=(EditText)findViewById(R.id.search);
btn_next=(Button)findViewById(R.id.btnnext);
btn_search=(Button)findViewById(R.id.btnsearch);
title=(TextView)findViewById(R.id.tv_title);
btn_search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
cross.setVisibility(View.VISIBLE);
title.setVisibility(View.INVISIBLE);
et.setVisibility(View.VISIBLE);
}
});
cross.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
title.setVisibility(View.INVISIBLE);
btn_search.setVisibility(View.VISIBLE);
}
});
btn_next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, Subheading.class);
startActivity(i);
}
});
listView = (ListView) findViewById(R.id.listView);
sendRequest();
pDialog = new ProgressDialog(this);
// Showing progress dialog before making http request
pDialog.setMessage("Loading...");
pDialog.show();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// String product = ((TextView) view).getText().toString();
Intent i=new Intent(getApplicationContext(),Subcontent_main.class);
startActivity(i);
}
});
}
private void sendRequest(){
StringRequest stringRequest = new StringRequest(JSON_URL,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
showJSON(response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,error.getMessage(),Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void showJSON(String json){
ParseJSON_Heading pj = new ParseJSON_Heading(json);
pj.parseJSON();
CustomList cl = new CustomList(this, ParseJSON_Heading.heading,ParseJSON_Heading.from,ParseJSON_Heading.to);
listView.setAdapter(cl);
hidePDialog();
}
private void hidePDialog() {
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
}`
public class ParseJSON_Heading {
public static String[] heading;
public static String[] from;
public static String[] to;
public static String[] id;
public static final String JSON_ARRAY_SUBHEADING = "tbl_heading";
public static final String JSON_ARRAY_HEADING = "tbl_heading";
public static final String KEY__HEADING_ID = "intheadingId";
public static final String KEY_TEXT_HEADING = "vchheading";
public static final String KEY_TEXT_FROM = "vchfrom";
public static final String KEY_TEXT_TO = "vchto";
private JSONArray users = null;
private String json;
public ParseJSON_Heading(String json){
this.json = json;
}
protected void parseJSON(){
JSONObject jsonObject=null;
try {
jsonObject = new JSONObject(json);
users = jsonObject.getJSONArray(JSON_ARRAY_HEADING);
id=new String[users.length()];
heading = new String[users.length()];
from = new String[users.length()];
to = new String[users.length()];
for(int i=0;i<users.length();i++){
JSONObject jo = users.getJSONObject(i);
id[i]=jo.getString(KEY__HEADING_ID);
heading[i] = jo.getString(KEY_TEXT_HEADING);
from[i] = jo.getString(KEY_TEXT_FROM);
to[i] = jo.getString(KEY_TEXT_TO);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
If you need to submit request parameters, then you have to override the getParams() method which should return list of parameters to be sent in a key value format.
In the code below we submit name, email and password as request parameters.
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
url, null,
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
pDialog.hide();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
pDialog.hide();
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("name", "foo");
params.put("email", "abc#gmail.com");
params.put("password", "foobar");
return params;
}
};
Related
my backend is laravel and i want to send json file to a specific rout
i already create my json plz help
public class MainActivity extends AppCompatActivity {
EditText usernameview;
EditText passwordview;
private static final String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameview = (EditText)findViewById(R.id.username) ;
passwordview = (EditText)findViewById(R.id.password) ;
Button login = (Button) findViewById(R.id.loginid);
}
public void senddatatoserver(View v) {
String username= usernameview.getText().toString();
String password = passwordview.getText().toString();
JSONObject login = new JSONObject();
try {
login.put("username",username);
login.put("password",password);
} catch (JSONException e) {
e.printStackTrace();
}
if (login.length() > 0) {
new SendDataToServer().execute(String.valueOf(login));
}
}
here is my class to send data i just wanna know what i should write in doinbackground methode
class SendDataToServer extends AsyncTask<String,String,String> {
#Override
protected String doInBackground(String... params) {
}
#Override
protected void onPostExecute(String s) {
}
}
you can use volley to send request
StringRequest stringRequest = new StringRequest(Request.Method.POST, YOUR_URL,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
for (int i = 0; i < response.length(); i++) {
JSONObject json; // convert String to JSONObject
try {
json = new JSONObject(response);
JSONArray jsonArray = json.getJSONArray("data");
lyric_string = jsonArray.getJSONObject(0).getString("song_lyric");
artist_string = jsonArray.getJSONObject(0).getString("song_artist");
//album_string = jsonArray.getJSONObject(0).getString("song_album");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
//error message
dismissDialog();
lyric.setText("Sorry No Lyric Found");
lyric.setVisibility(View.VISIBLE);
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("song_name", "A song Name");
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
hi i have an app shows the online streamers from Twitch.tv and the data comes from request i send but i cant parse them this is my code
public ArrayList<Twitch> ParseTwitch(JSONArray object, Context context){
ArrayList<Twitch> chanels = new ArrayList<>();
try {
for (int i = 0;i<object.length();i++){
JSONObject streamObjct = object.getJSONObject(i);
JSONObject chanel = streamObjct.getJSONObject("channel");
JSONObject url= streamObjct.getJSONObject("preview");
final Twitch twitch = new Twitch();
twitch.setName(chanel.getString(CHANEL_NAME));
twitch.setStatus(chanel.getString(CHANEL_STATUS));
twitch.setGame(streamObjct.getString(GAME));
twitch.setLanguage(chanel.getString(BROADCASTER_LANGUAGE));
twitch.setViewrs(streamObjct.getInt(VIEWRS));
String imageUrl = url.getString("medium");
ImageRequest request =new ImageRequest(imageUrl, new Response.Listener<Bitmap>() {
#Override
public void onResponse(Bitmap response) {
twitch.setLogo(response);
}
}, 0, 0, null, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue quew = Volley.newRequestQueue(context);
quew.add(request);
chanels.add(twitch);
}
return chanels;
}catch (JSONException e){
e.printStackTrace();
}
return chanels;
}
and this my request
https://api.twitch.tv/kraken/search/streams?query=poker&client_id=gxdzx71jhztgyypn4kjemm1htovv1o
at least can anyone tell me should i work with sqlite Database or not?
where i called TwitchParcer
private void prepareData(String url, final ListView mListView) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray stream = response.getJSONArray("streams");
TwitchApiParser parser = new TwitchApiParser();
ArrayList items= parser.ParseTwitch(stream);
TwitchAdapter adapter = new TwitchAdapter(getContext(),
R.layout.activity_last_news_fragment,items);
mListView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), "Ridi Bro", Toast.LENGTH_SHORT).show();
}
});
RequestQueue quew = Volley.newRequestQueue(getActivity().getApplicationContext());
quew.add(request);
}
and this is new Error
Process: app.mma.introsliderproject, PID: 11542
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at app.mma.PokerInfo.twitch.TwitchAdapter.getView(TwitchAdapter.java:39)
i solve the problem this is the complete code
public class TwitchFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.twitch_main, container, false);
String url="http://192.168.1.101/mySite/Flowers/flowers2.json";
ListView mListView = (ListView) view.findViewById(R.id.twitch_last);
prepareData(url,mListView);
return view;
}
private void prepareData(String url, final ListView mListView) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray stream = response.getJSONArray("streams");
TwitchApiParser parser = new TwitchApiParser();
ArrayList items= parser.ParseTwitch(stream,getActivity().getApplicationContext());
TwitchAdapter adapter = new TwitchAdapter(getContext(),
R.layout.twitch,items);
mListView.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getContext(), "Ridi Bro", Toast.LENGTH_SHORT).show();
}
});
RequestQueue quew = Volley.newRequestQueue(getActivity().getApplicationContext());
quew.add(request);
}
and the parser
public class TwitchApiParser {
private final String CHANEL_NAME="display_name";
private final String GAME="game";
private final String CHANEL_STATUS = "status";
private final String BROADCASTER_LANGUAGE = "broadcaster_language";
private final String VIEWRS = "viewers";
public ArrayList<Twitch> ParseTwitch(JSONArray object, Context context){
ArrayList<Twitch> chanels = new ArrayList<>();
try {
for (int i = 0;i<object.length();i++){
JSONObject streamObjct = object.getJSONObject(i);
JSONObject chanel = streamObjct.getJSONObject("channel");
JSONObject url= streamObjct.getJSONObject("preview");
final Twitch twitch = new Twitch();
twitch.setName(chanel.getString(CHANEL_NAME));
twitch.setStatus(chanel.getString(CHANEL_STATUS));
twitch.setGame(streamObjct.getString(GAME));
twitch.setLanguage(chanel.getString(BROADCASTER_LANGUAGE));
twitch.setViewrs(streamObjct.getInt(VIEWRS));
String imageUrl = url.getString("medium");
ImageRequest request =new ImageRequest(imageUrl, new Response.Listener<Bitmap>() {
#Override
public void onResponse(Bitmap response) {
twitch.setLogo(response);
}
}, 0, 0, null, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue quew = Volley.newRequestQueue(context);
quew.add(request);
chanels.add(twitch);
}
return chanels;
}catch (JSONException e){
e.printStackTrace();
}
return chanels;
}
i am trying to post data on server using volley but it just give me Volley.ServerError when i click on submit button.But also When i debug my app then all parameters get value but instead of that their is error.
public class ConnectWithSpeaker extends AppCompatActivity implements
View.OnClickListener {
LinearLayout linear_layoutcontainer;
Toolbar toolbar;
String url = Constants.SUBMIT_API;
public static final String KEY_NAME = "name";
public static final String KEY_EMAIL = "email";
public static final String KEY_MOBILE = "mobile";
public static final String KEY_COMPANY = "company";
public static final String KEY_SPEAKERID = "speaker_id";
String s_id;
private EditText u_name;
private EditText u_email;
private EditText u_mobile;
private EditText u_company;
private Button submit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connect_with_speaker);
linear_layoutcontainer = (LinearLayout) findViewById(R.id.linear_layoutcontainer);
toolbar = (Toolbar) findViewById(R.id.customtoolbar);
TextView title = (TextView) toolbar.findViewById(R.id.title);
title.setText("Connect with Speakers");
toolbar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
u_name = (EditText) findViewById(R.id.name);
u_email = (EditText) findViewById(R.id.email);
u_mobile = (EditText) findViewById(R.id.mobile);
u_company = (EditText) findViewById(R.id.compny_name);
submit = (Button) findViewById(R.id.connect);
submit.setOnClickListener(this);
s_id = getIntent().getStringExtra("speakerid");
}
private void submitdetails() {
final String name = u_name.getText().toString().trim(); //trim() remove spaces after&before string
final String email = u_email.getText().toString().trim();
final String mobile = u_mobile.getText().toString().trim();
final String company = u_company.getText().toString().trim();
final String speaker_id = s_id;
Toast.makeText(ConnectWithSpeaker.this, "submit details", Toast.LENGTH_SHORT).show();
CustomJSONObjectRequest request2 = new CustomJSONObjectRequest(Request.Method.POST, url, new
Response.Listener<String>() {
#Override
public void onResponse(String response) {
System.out.println("Response........"+response);
if (response.trim().equals("success")) {
Toast.makeText(getApplicationContext(), "Your request is proceed, we will update you with further updates.",
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(ConnectWithSpeaker.this, volleyError.toString(), Toast.LENGTH_LONG).show();
}
}) {
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_NAME, name);
params.put(KEY_EMAIL, email);
params.put(KEY_MOBILE, mobile);
params.put(KEY_COMPANY, company);
params.put(KEY_SPEAKERID, speaker_id);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(request2);
}
#Override
public void onClick(View v) {
if (v == submit) {
if (TextUtils.isEmpty(u_name.getText().toString())) {
u_name.setError("Enter Name");
u_name.requestFocus();
}
if (TextUtils.isEmpty(u_email.getText().toString())) {
u_email.setError("Enter Email");
u_email.requestFocus();
}
if ((TextUtils.isEmpty(u_mobile.getText().toString())) || (u_mobile.length() < 10 || u_mobile.length() > 15)) {
u_mobile.setError("Enter valid Mobile No");
u_mobile.requestFocus();
}
if (TextUtils.isEmpty(u_company.getText().toString())) {
u_company.setError("Enter Company Name");
u_company.requestFocus();
} else {
submitdetails();
}
}
}
This is the error in logcat.
E/Volley: [1515] BasicNetwork.performRequest: Unexpected response code 400 for http://
I am using this.
public class AEJsonRequest extends JsonObjectRequest {
private static int mStatusCode;
public AEJsonRequest(int method, String url, JSONObject jsonRequest,
Response.Listener<JSONObject> listener,
Response.ErrorListener errorListener) {
super(method, url, jsonRequest, listener, errorListener);
ServerHandler.bwLog("sending params", jsonRequest.toString());
}
public AEJsonRequest(String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener,
Response.ErrorListener errorListener) {
super(url, jsonRequest, listener, errorListener);
}
public static int getStatusCode() {
return mStatusCode;
}
#Override
protected VolleyError parseNetworkError(VolleyError volleyError) {
if (volleyError.networkResponse != null && volleyError.networkResponse.data != null) {
mStatusCode = volleyError.networkResponse.statusCode;
ServerHandler.bwLog("Error Status code", "" + mStatusCode);
VolleyError error = new VolleyError(new String(volleyError.networkResponse.data));
volleyError = error;
}
return volleyError;
}
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
//params.put("Content-Type", "application/x-www-form-urlencoded");
params.put("Accept", "application/json");
params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
}
and call it to
public void submitDetail(HashMap<String, String> hashMap) throws JSONException {
//param is the JSONobject
final AEJsonRequest jsonRequest = new AEJsonRequest(Request.Method.POST, "url", new JSONObject(hashMap),
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
// if status is true, it will return the json data to its calling activity
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
MAX_TIMEOUT_MS,
0,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
AppController.getInstance().addToRequestQueue(jsonRequest);
}
Hope this'd help
In my Project if I add parameters with url and then make a request that is being received by the server. But if I use GET params method then the request is not being received by the server.
Successful request
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText name1=(EditText)findViewById(R.id.editText);
final EditText price1=(EditText)findViewById(R.id.editText2);
final EditText description1=(EditText)findViewById(R.id.editText3);
Button submit=(Button)findViewById(R.id.button);
submit.setOnClickListener(new View.OnClickListener() {
#Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
#Override
public void onClick(View v) {
final String name=name1.getText().toString();
final double price= Double.parseDouble(price1.getText().toString());
final String description=description1.getText().toString();
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
String url ="http://192.168.0.101/webservice/create_product.php?name=symphony&price=1000&description=from_android";
StringRequest sr=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject jo=new JSONObject(response);
Log.d("From Volley",+jo.getInt("success")+" "+jo.getString("message"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("From Volley", error.getMessage());
}
});
Log.d("From Volley",sr.getUrl()+" "+sr.toString());
queue.add(sr);
}
});
}
}
Failed request
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText name1=(EditText)findViewById(R.id.editText);
final EditText price1=(EditText)findViewById(R.id.editText2);
final EditText description1=(EditText)findViewById(R.id.editText3);
Button submit=(Button)findViewById(R.id.button);
submit.setOnClickListener(new View.OnClickListener() {
#Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
#Override
public void onClick(View v) {
final String name=name1.getText().toString();
final double price= Double.parseDouble(price1.getText().toString());
final String description=description1.getText().toString();
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
String url ="http://192.168.0.101/webservice/create_product.php";
StringRequest sr=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject jo=new JSONObject(response);
Log.d("From Volley",+jo.getInt("success")+" "+jo.getString("message"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("From Volley", error.getMessage());
}
}){
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("name",name);
params.put("price", String.valueOf(price));
params.put("description",description);
return params;
}
};
Log.d("From Volley",sr.getUrl()+" "+sr.toString());
queue.add(sr);
}
});
}
}
Here you use GET method that you have to build URL before make request, getParams() is used when request method is post...
Build URL for GET As follow
Uri.Builder builder = new Uri.Builder();
builder.scheme("http")
.authority("192.168.0.101")
.appendPath("webservice")
.appendPath("create_product.php")
.appendQueryParameter("name", name)
.appendQueryParameter("price", String.valueOf(price))
.appendQueryParameter("description", description);
String url = builder.build().toString();
StringRequest sr=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
}
change to
StringRequest sr=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
}
I want to access my Android apps through Web-Service.
but getting error in my android app ,
i am using volley & POST method for login.. `public class Main extends AppCompatActivity implements View.OnClickListener
{
public static final String LOGIN_URL = "http://10.54.103.8:4067/evivaservices/Webservices/login";
public static final String KEY_USERNAME="username";
public static final String KEY_PASSWORD="password";
private EditText editTextUsername;
private EditText editTextPassword;
private Button buttonLogin;
private String username;
private String password;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_layout);
editTextUsername = (EditText) findViewById(R.id.username1);
editTextPassword = (EditText) findViewById(R.id.password1);
buttonLogin = (Button) findViewById(R.id.login_button);
buttonLogin.setOnClickListener(this);
}
private void userLogin() {
username = editTextUsername.getText().toString().trim();
password = editTextPassword.getText().toString().trim();
StringRequest stringRequest = new StringRequest(Request.Method.POST, LOGIN_URL,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try
{
JSONObject jsonObject = new JSONObject(response);
Next();
}
catch(JSONException e)
{
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),error.toString(), Toast.LENGTH_LONG ).show();
}
}){
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map = new HashMap<String,String>();
map.put(KEY_USERNAME,username);
map.put(KEY_PASSWORD,password);
return map;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void Next(){
Intent intent = new Intent(this, HomeScreen.class);
intent.putExtra(KEY_USERNAME, username);
startActivity(intent);
}
#Override
public void onClick(View v)
{
userLogin();
}
}
`
JSON DATA
{
"id": 31,
"username": "andrew.cope#services.co.in",
"user_image": "http:\/\/103.54.103.8:4067\/evivaservices\/img\/profile_31.png",
"err-code": 0
}
`
Please change your StringRequest to JsonRequest as below:
JsonRequest jsonRequest = new JsonRequest(Request.Method.POST, LOGIN_URL, new Response.Listener<>() {
#Override
public void onResponse(Object response) {
try {
Next();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();
}
}) {
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> map = new HashMap<String, String>();
map.put(KEY_USERNAME, username);
map.put(KEY_PASSWORD, password);
return map;
}
#Override
protected Response parseNetworkResponse(NetworkResponse response) {
return null;
}
#Override
public int compareTo(Object another) {
return 0;
}
};
Thank You.
Hello dear you made a mistake while you parsing the response
JSONArray jsonArray=jsonObject.getJSONArray("err-code")
remove above the line and then parse again.
In you JSON DATA, I not find array, so you shouldn't use JsonArray, you can delete this line in your code :JSONArray jsonArray=jsonObject.getJSONArray("err-code").