简体   繁体   中英

Volley jsonArray Request not working

I am making jsonArray request using volley but onError() gets executed all the time though I have added dependency, internet permission. Here is my request code

RequestQueue requestQueue = Volley.newRequestQueue(this);

    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, "http://api.aladhan.com/v1/timingsByCity?city=Dubai&country=United%20Arab%20Emirates", null, new Response.Listener<JSONArray>() {
        @Override
        public void onResponse(JSONArray response) {
            try {
                JSONObject obj = (JSONObject) response.get(0);
                Toast.makeText(City_Timing.this, obj.getString("Fajr"), Toast.LENGTH_SHORT).show();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(City_Timing.this, "Error", Toast.LENGTH_SHORT).show();
        }
    });
    requestQueue.add(jsonArrayRequest);

My AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="anandroid.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">

    </activity>
    <activity android:name=".Search_CIty"
        android:label="SEARCH CITY"
        android:parentActivityName=".MainActivity"/>
    <activity android:name=".City_Timing"
        android:label="TIMING"
        android:parentActivityName=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".History"
        android:label="HISTORY"
        android:parentActivityName=".MainActivity"/>
    <activity android:name=".AboutUS"
        android:label="ABOUT US"
        android:parentActivityName=".MainActivity"/>

</application>

Only toast of onError is displaying. I have tried to change the request type to string, JsonObject request but nothing working, only on error is executed all the time.

You have got a typo error in internet permission, change

<uses-permission android:name="anandroid.permission.INTERNET"/>

to

<uses-permission android:name="android.permission.INTERNET" />

it should be android not anandroid

please check your menifest:

there is a spelling mistake in anandroid

<uses-permission android:name="anandroid.permission.INTERNET"/>

change to

<uses-permission android:name="android.permission.INTERNET"/>

it works fine try this and let me know

Just change this,

<uses-permission android:name="anandroid.permission.INTERNET"/>

To,

<uses-permission android:name="android.permission.INTERNET" />

You just got a typo error, nothing else.

Try This

 <uses-permission android:name="anandroid.permission.INTERNET"/>

instead of this

<uses-permission android:name="android.permission.INTERNET" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM