java - getLastKnownLocation 导致我的应用程序崩溃
问题描述
尝试运行我的应用程序时遇到此问题。当我到达标记的代码行时它会崩溃。我确定问题存在,因为当我删除这些行时应用程序会运行。有人可以帮我解决这个错误吗?
私人无效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); */
}
}
您的帮助将不胜感激
解决方案
推荐阅读
- javascript - 使用 JavaScript 下载命名 blob 而不创建隐藏的 DOM 元素
- bash - 在 ifeq 期间 Makefile 变量值不可用
- c++ - 在什么情况下 MSVC C++ 编译器有时会在函数 operator new[] 返回的指针之前直接写入数组大小?
- scikit-learn - TypeError:join() 参数必须是 str 或 bytes,而不是 'TextIOWrapper
- python - 为什么打开文件时python架子模块在启动时会出错
- python - 对文件夹进行计算
- c# - MVC 在另一个视图中的弹出模式内渲染部分视图 foreach
- asp.net - 表单击的 asp.net 事件处理程序被调用两次
- python - 人物图片网格
- git - 如何从我的 oh-my-posh/posh-git 显示中删除红色基础字形?