Volley JsonObject Request (method get) not working

Volley JsonObject Request (method get) not working



I am using volley for connecting to my rest web service. I have an .php address that return a json object. I use this code in my android app to get this object:


public void getData()
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.show();

JsonObjectRequest jsonArrayRequest = new JsonObjectRequest(Request.Method.GET,URI_AZMOON_QUESTIONS,null,
new Response.Listener<JSONObject>()
@Override
public void onResponse(JSONObject response)
String s="t";

, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
Log.e("Volley", error.toString());
progressDialog.dismiss();

);
requestQueue.add(jsonArrayRequest);



but this request never runnig. I mean when I debug the program it never go to the onResponse and onErrorResponse methods.


onResponse


onErrorResponse



Update

this my Code:


import android.app.ProgressDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonArrayRequest;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.shaz.zist.Adapter.AzmoonsAdapter;
import com.shaz.zist.Models.AzmoonQuestion;

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

import java.util.ArrayList;
import java.util.List;

import WebService.WebService;


public class GroupQuizActivity extends AppCompatActivity implements View.OnClickListener
public static final String URI_AZMOON_QUESTIONS = "http://zahra-t.zili.ir/azmoon/read.php";
List<AzmoonQuestion> azmoons=new ArrayList<>();
AzmoonsAdapter adapter;
LinearLayout noNetwork;
ListView azmoonList;
ImageView refresh;
RequestQueue requestQueue;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group_quiz);
noNetwork=findViewById(R.id.noconection);
azmoonList=findViewById(R.id.quizesList);
refresh=findViewById(R.id.refresh);
refresh.setOnClickListener(this);
requestQueue = Volley.newRequestQueue(this);
checkNetworkConnection();


private void checkNetworkConnection()
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
boolean netResult=false;
if(connectivityManager.getActiveNetworkInfo()!=null)
netResult=connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting();
if(!netResult)
noNetwork.setVisibility(View.VISIBLE);

else
noNetwork.setVisibility(View.GONE);
setUpListView();



private void setUpListView()
WebService wb=new WebService(this,azmoons);
adapter=new AzmoonsAdapter(this,azmoons);
azmoonList.setAdapter(adapter);
getData();


@Override
public void onClick(View v)
switch (v.getId())
case R.id.refresh:
checkNetworkConnection();
break;



public void getData()
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading...");
progressDialog.show();
/*StringRequest rs=new StringRequest(URI_AZMOON_QUESTIONS, new Response.Listener<String>()
@Override
public void onResponse(String response)
String ss=response;

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


);*/
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, URI_AZMOON_QUESTIONS, null,
new Response.Listener<JSONArray>()
@Override
public void onResponse(JSONArray response)


, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
Log.e("Volley", error.toString());
progressDialog.dismiss();

);
requestQueue.add(jsonArrayRequest);






but this request never runnig. Means can u explain more?
– Nilesh Rathod
Sep 1 at 6:06



but this request never runnig.





I edit my question
– BeginnerProgrammer
Sep 1 at 6:09





Do you have internet permission enabled in manifest?, Also try to log your onResponse message.
– W4R10CK
Sep 1 at 7:49





@W4R10CK yes i have added it.
– BeginnerProgrammer
Sep 1 at 9:35






Please share the entire code of activity.
– W4R10CK
Sep 1 at 9:37




1 Answer
1



try StringRequest intead of JsonArrayRequest (StringRequest always works for me)


StringRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, URI_AZMOON_QUESTIONS,
new Response.Listener<String>() @Override
public void onResponse(JSONArray response)


, new Response.ErrorListener()
@Override
public void onErrorResponse(VolleyError error)
Log.e("Volley", error.toString());
progressDialog.dismiss();

);
requestQueue.add(jsonArrayRequest);
}



Thanks for contributing an answer to Stack Overflow!



But avoid



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



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



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



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế