[問題] 使用method問題
想使用別的Java檔中的method
public void locationServiceInitial()
{
lms = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider = lms.getBestProvider(criteria, true);
Location location = lms.getLastKnownLocation(bestProvider);
getLocation(location);
}
private void getLocation(Location location)
{
if(location != null) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
else {
Toast.makeText(this, "無法定位座標", Toast.LENGTH_LONG).show();
}
}
而我在想要呼叫method 的地方寫
public LatitudeAndLongitude LatitudeAndLongitude;
LatitudeAndLongitude = new LatitudeAndLongitude();
LatitudeAndLongitude.locationServiceInitial();
在實機跑的時候,就會程式崩潰,請問該如何解決?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.138.152.7
推
07/24 18:26, , 1F
07/24 18:26, 1F
推
07/24 22:01, , 2F
07/24 22:01, 2F
→
07/24 23:58, , 3F
07/24 23:58, 3F