Android giving error while accessing json data from the internet

I am a beginner, building a goofy app that uses an online API. I uploaded the .json file to GitHub, from where my app accesses it and gives the output. However, it always runs the statements for onErrorResponse. Am I doing something wrong? Here’s the code for MainActivity:

package com.example.jsonparsing;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DownloadManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

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.Volley;

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

public class MainActivity extends AppCompatActivity {
    RequestQueue requestQueue;
    Button search;
    EditText input;
    TextView word;
    TextView meaning;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        search = findViewById(R.id.button_getMeaning);
        input = findViewById(R.id.editText_input);
        word = findViewById(R.id.textView_word);
        meaning = findViewById(R.id.textView_meaning);
        requestQueue = Volley.newRequestQueue(this);

        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String term = input.getText().toString().toLowerCase();
                String displayInput = term.toUpperCase() + ":";
                word.setText(displayInput);

                JsonObjectRequest jsonObjectRequest1 = new JsonObjectRequest(Request.Method.GET, "https://github.com/DeathVenom54/bonerDictionaryDatabase/blob/master/definitions.json", null,
                        new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                try {
                                    String definition = response.getString(term);
                                    meaning.setText(definition);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                    meaning.setText("Sorry, this word doesn't exist in the boner database.");
                                }
                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(MainActivity.this, "Connection error, please check internet connection.", Toast.LENGTH_SHORT).show();
                    }
                });
                requestQueue.add(jsonObjectRequest1);
            }
        });




    }
}

The project uses Volley and I have added Internet permission in the manifest.

Edit: here’s the .json : https://github.com/DeathVenom54/bonerDictionaryDatabase/blob/master/definitions.json

Answer

The json url you have posted is a link to someone’s github page with the json, but not the json itself. Whats most likely happening is volley is downloading the HTML page in its entirety which contains the json. Its then complaining that its not correctly formatted json.

If you want that json directly you need to find a way to host it somewhere. For example github has an api that you can access json files like this https://api.github.com/users/mralexgray/repos

For local testing you could always copy it into a local json file and import into the res/raw of your app and reference it from there.