Java getLastKnownLocation导致我的应用程序崩溃

Java getLastKnownLocation导致我的应用程序崩溃,java,android,android-studio,Java,Android,Android Studio,我在尝试运行我的应用程序时遇到此问题。当我到达标记的代码行时,它会崩溃。我确信问题存在,因为当我删除这些代码行时,应用程序会运行。有人能帮我纠正这个错误吗 私有void getLocation(){ 如果您能提供帮助,我们将不胜感激。发布堆栈跟踪。您可能没有权限。您是否在清单和运行时请求了这些权限?是的,我的清单文件如下所示: //Check Permissions again if (ActivityCompat.checkSelfPermission(Reclamation

我在尝试运行我的应用程序时遇到此问题。当我到达标记的代码行时,它会崩溃。我确信问题存在,因为当我删除这些代码行时,应用程序会运行。有人能帮我纠正这个错误吗

私有void getLocation(){


如果您能提供帮助,我们将不胜感激。

发布堆栈跟踪。您可能没有权限。您是否在清单和运行时请求了这些权限?是的,我的清单文件如下所示:
    //Check Permissions again

    if (ActivityCompat.checkSelfPermission(Reclamation.this,Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(Reclamation.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 LocalPassive= 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);
        }
        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);
        }
        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);
        }
        else
        {
            Toast.makeText(this, "Can't Get Your Location", Toast.LENGTH_SHORT).show();
        }

        Intent intent = new Intent(Reclamation.this,SetLocation.class);
        intent.putExtra("latt",latitude);
        intent.putExtra("lonn",longitude);
       // startActivityForResult(intent, 3); */
    }

}