title: Getting error in Fetching news api from newsapi.org
body: <p>I am making News App using Newsapi.org API key I have written all the code and compiled successfully but app is not fetching any data through that key.</p>
  <hr />
  <p>This is my MainActivity.java file</p>
  <pre><code>    package com.example.newsindia;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.app.LoaderManager;
  import android.content.Context;
  import android.content.Intent;
  import android.content.Loader;
  import android.content.SharedPreferences;
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  import android.net.Uri;
  import android.os.Bundle;
  import android.preference.PreferenceManager;
  import android.view.Menu;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks&lt;List&lt;News&gt;&gt; {
      private NewsAdapter mAdapter;
      private TextView mEmptyStateTextView;
      private static final int EARTHQUAKE_LOADER_ID = 1;
      public static final String LOG_TAG = MainActivity.class.getName();
      private static final String NEWS_REQUEST_URL = &quot;http://newsapi.org/v2/top-headlines?country=in&amp;apiKey=7615387a23b04e68b9f2b79719d19786&quot;;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          ListView newsListView = (ListView) findViewById(R.id.list);
          mAdapter=new NewsAdapter(this, new ArrayList&lt;&gt;());
          newsListView.setAdapter(mAdapter);
          mEmptyStateTextView = (TextView) findViewById(R.id.empty_view);
          newsListView.setEmptyView(mEmptyStateTextView);
          newsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long l) {
                  // Find the current earthquake that was clicked on
                  News currentEarthquake = mAdapter.getItem(position);
  
                  // Convert the String URL into a URI object (to pass into the Intent constructor)
                  Uri earthquakeUri = Uri.parse(currentEarthquake.getmUrl());
  
                  // Create a new intent to view the earthquake URI
                  Intent websiteIntent = new Intent(Intent.ACTION_VIEW, earthquakeUri);
  
                  // Send the intent to launch a new activity
                  startActivity(websiteIntent);
              }
          });
  
  
          // Get a reference to the ConnectivityManager to check state of network connectivity
          ConnectivityManager connMgr = (ConnectivityManager)
                  getSystemService(Context.CONNECTIVITY_SERVICE);
  
          // Get details on the currently active default data network
          NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
          // Start the AsyncTask to fetch the earthquake data
  
          if (networkInfo != null &amp;&amp; networkInfo.isConnected()) {
              // Get a reference to the LoaderManager, in order to interact with loaders.
              LoaderManager loaderManager = getLoaderManager();
  
              // Initialize the loader. Pass in the int ID constant defined above and pass in null for
              // the bundle. Pass in this activity for the LoaderCallbacks parameter (which is valid
              // because this activity implements the LoaderCallbacks interface).
              loaderManager.initLoader(EARTHQUAKE_LOADER_ID, null, this);
          }
          else {
              // Otherwise, display error
              // First, hide loading indicator so error message will be visible
              View loadingIndicator = findViewById(R.id.loading_indicator);
              loadingIndicator.setVisibility(View.GONE);
  
              // Update empty state with no connection error message
              mEmptyStateTextView.setText(R.string.no_internet_connection);
          }
      }
  
      @Override
      public Loader&lt;List&lt;News&gt;&gt; onCreateLoader(int i, Bundle bundle) {
  
  
  
  
          Uri baseUri = Uri.parse(NEWS_REQUEST_URL);
          Uri.Builder uriBuilder = baseUri.buildUpon();
  
          uriBuilder.appendQueryParameter(&quot;format&quot;, &quot;geojson&quot;);
          uriBuilder.appendQueryParameter(&quot;limit&quot;, &quot;10&quot;);
  
          return new NewsLoader(this, uriBuilder.toString());
      }
  
      @Override
      public void onLoadFinished(Loader&lt;List&lt;News&gt;&gt; loader, List&lt;News&gt; earthquakes) {
          // Clear the adapter of previous earthquake data
          // Hide loading indicator because the data has been loaded
          View loadingIndicator = findViewById(R.id.loading_indicator);
          loadingIndicator.setVisibility(View.GONE);
          mAdapter.clear();
  
          // If there is a valid list of {@link Earthquake}s, then add them to the adapter's
          // data set. This will trigger the ListView to update.
          if (earthquakes != null &amp;&amp; !earthquakes.isEmpty()) {
              mAdapter.addAll(earthquakes);
          }
          // Set empty state text to display &quot;No earthquakes found.&quot;
          mEmptyStateTextView.setText(R.string.no_earthquakes);
      }
  
      @Override
      public void onLoaderReset(Loader&lt;List&lt;News&gt;&gt; loader) {
          // Loader reset, so we can clear out our existing data.
          mAdapter.clear();
      }
  
  
      }
  </code></pre>
  <hr />
  <p>This is my QuerUtils.java class</p>
  <pre><code>package com.example.newsindia;
  
  import android.text.TextUtils;
  import android.util.Log;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.nio.charset.Charset;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  import static com.example.newsindia.MainActivity.LOG_TAG;
  import static java.lang.Long.parseLong;
  
  public final class QueryUtils {
      private QueryUtils() {
  
      }
      public static long parseLong(String s)
      {
          long timeInMilliseconds = Long.parseLong(s);
  
          return timeInMilliseconds;
      }
      private static String formatTime(Date dateObject) {
          SimpleDateFormat timeFormat = new SimpleDateFormat(&quot;h:mm a&quot;);
          return timeFormat.format(dateObject);
      }
  
      /**
       * Return a list of {@link } objects that has been built up from
       * parsing the given JSON response.
       */
      private static List&lt;News&gt; extractFeatureFromJson(String earthquakeJSON) {
          if (TextUtils.isEmpty(earthquakeJSON)) {
              return null;
          }
          // Create an empty ArrayList that we can start adding earthquakes to
          // Create an empty ArrayList that we can start adding earthquakes to
          List&lt;News&gt; earthquakes = new ArrayList&lt;&gt;();
  
          // Try to parse the SAMPLE_JSON_RESPONSE. If there's a problem with the way the JSON
          // is formatted, a JSONException exception object will be thrown.
          // Catch the exception so the app doesn't crash, and print the error message to the logs.
          try {
  
  
              // build up a list of Earthquake objects with the corresponding data.
              JSONObject root= new JSONObject(earthquakeJSON);
              JSONArray earthquakeArray= root.getJSONArray(&quot;articles&quot;);
              for(int i =0;i&lt;earthquakeArray.length();i++)
              {
                  JSONObject currentEarthquake= earthquakeArray.getJSONObject(i);
  
                  String title = currentEarthquake.getString(&quot;title&quot;);
                  String description= currentEarthquake.getString(&quot;description&quot;);
                  String image= currentEarthquake.getString(&quot;urlToImage&quot;);
                  // Extract the value for the key called &quot;url&quot;
                  String url = currentEarthquake.getString(&quot;url&quot;);
                  String time=currentEarthquake.getString(&quot;publishedAt&quot;);
  
                  long ans= parseLong(time);
                  Date dateObject = new Date(ans);
  
                  String timing= formatTime(dateObject);
                  News earthQuakes = new News(title,description,image,timing,url);
                  earthquakes.add(earthQuakes);
              }
  
          } catch (JSONException e) {
              // If an error is thrown when executing any of the above statements in the &quot;try&quot; block,
              // catch the exception here, so the app doesn't crash. Print a log message
              // with the message from the exception.
              Log.e(&quot;QueryUtils&quot;, &quot;Problem parsing the earthquake JSON results&quot;, e);
          }
  
          // Return the list of earthquakes
          return earthquakes;
      }
  
  
  
      List&lt;News&gt; earthquakes = new ArrayList&lt;&gt;();
      private static URL createUrl(String stringUrl) {
          URL url = null;
          try {
              url = new URL(stringUrl);
          } catch (MalformedURLException e) {
              Log.e(LOG_TAG, &quot;Problem building the URL &quot;, e);
          }
          return url;
      }
  
      /**
       * Make an HTTP request to the given URL and return a String as the response.
       */
      private static String makeHttpRequest(URL url) throws IOException {
          String jsonResponse = &quot;&quot;;
  
          // If the URL is null, then return early.
          if (url == null) {
              return jsonResponse;
          }
  
          HttpURLConnection urlConnection = null;
          InputStream inputStream = null;
          try {
              urlConnection = (HttpURLConnection) url.openConnection();
              urlConnection.setReadTimeout(10000 /* milliseconds */);
              urlConnection.setConnectTimeout(15000 /* milliseconds */);
              urlConnection.setRequestMethod(&quot;GET&quot;);
              urlConnection.connect();
  
              // If the request was successful (response code 200),
              // then read the input stream and parse the response.
              if (urlConnection.getResponseCode() == 200) {
                  inputStream = urlConnection.getInputStream();
                  jsonResponse = readFromStream(inputStream);
              } else {
                  Log.e(LOG_TAG, &quot;Error response code: &quot; + urlConnection.getResponseCode());
              }
          } catch (IOException e) {
              Log.e(LOG_TAG, &quot;Problem retrieving the earthquake JSON results.&quot;, e);
          } finally {
              if (urlConnection != null) {
                  urlConnection.disconnect();
              }
              if (inputStream != null) {
                  // Closing the input stream could throw an IOException, which is why
                  // the makeHttpRequest(URL url) method signature specifies than an IOException
                  // could be thrown.
                  inputStream.close();
              }
          }
          return jsonResponse;
      }
  
      /**
       * Convert the {@link InputStream} into a String which contains the
       * whole JSON response from the server.
       */
      private static String readFromStream(InputStream inputStream) throws IOException {
          StringBuilder output = new StringBuilder();
          if (inputStream != null) {
              InputStreamReader inputStreamReader = new InputStreamReader(inputStream, Charset.forName(&quot;UTF-8&quot;));
              BufferedReader reader = new BufferedReader(inputStreamReader);
              String line = reader.readLine();
              while (line != null) {
                  output.append(line);
                  line = reader.readLine();
              }
          }
          return output.toString();
      }
  
  
      /**
       * Query the USGS dataset and return a list of {@link } objects.
       */
      public static List&lt;News&gt; fetchEarthquakeData(String requestUrl) {
          // Create URL object
          URL url = createUrl(requestUrl);
  
          // Perform HTTP request to the URL and receive a JSON response back
          String jsonResponse = null;
          try {
              jsonResponse = makeHttpRequest(url);
          } catch (IOException e) {
              Log.e(LOG_TAG, &quot;Problem making the HTTP request.&quot;, e);
          }
  
          // Extract relevant fields from the JSON response and create a list of {@link Earthquake}s
          List&lt;News&gt; earthquakes = extractFeatureFromJson(jsonResponse);
  
          // Return the list of {@link Earthquake}s
          return earthquakes;
      }
  }
  </code></pre>
  <p>I Have created 3 more java files i.e NewsAdapter.java for displaying items with the help of listeview + Adapterview</p>
  <p>2nd --&gt; NewsLoader.java class to implement loader class</p>
  <p>3rd---&gt;News.java class which will return all the value from api like title,description,image,etc</p>