title: Getting error message during use of getLocation() function
body: <p>When I use <code>getLocation()</code> function for multiple times, Android studio gives me the error message <code>Can't Get Your Location</code>. 
  I always put the GPS activated on my testing device.</p>
  
  <p>Please help me,I am new to Android Studio and Java.
  forgive me for my English, It isn't my native language.</p>
  
  <pre><code>//location
  private void getLocation() {
  
      //Check Permissions again
      if (ActivityCompat.checkSelfPermission(MainActivity.this,Manifest.permission.ACCESS_FINE_LOCATION)
              != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(MainActivity.this,
              Manifest.permission.ACCESS_COARSE_LOCATION) !=PackageManager.PERMISSION_GRANTED)
      {
          ActivityCompat.requestPermissions(this,new String[]
                  {Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
      } else {
          Location LocationGps= locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          Location LocationNetwork=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
          Location LocationPassive=locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
  
          if (LocationGps !=null)
          {
              double lat=LocationGps.getLatitude();
              double longi=LocationGps.getLongitude();
  
              latitude=String.valueOf(lat);
              longitude=String.valueOf(longi);
              showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
              loc="http://www.google.com/maps/place/"+latitude+","+longitude;
          }
          else if (LocationNetwork !=null)
          {
              double lat=LocationNetwork.getLatitude();
              double longi=LocationNetwork.getLongitude();
  
              latitude=String.valueOf(lat);
              longitude=String.valueOf(longi);
              showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
              loc="http://www.google.com/maps/place/"+latitude+","+longitude;
  
          }
          else if (LocationPassive !=null)
          {
              double lat=LocationPassive.getLatitude();
              double longi=LocationPassive.getLongitude();
  
              latitude=String.valueOf(lat);
              longitude=String.valueOf(longi);
              showLocationTxt.setText("Your Location:"+"\n"+"Latitude= "+latitude+"\n"+"Longitude= "+longitude);
              loc="http://www.google.com/maps/place/"+latitude+","+longitude;
  
          } else {
              Toast.makeText(this, "Can't Get Your Location", Toast.LENGTH_SHORT).show();
          }
      }
  }
  </code></pre>