亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

片段中函數的無法訪問語句

片段中函數的無法訪問語句

藍山帝景 2023-10-12 15:01:25
我有一個片段,我想在其中顯示地圖,我現在已經這樣做了,但是當我調用函數時,它會拋出一個無法訪問的錯誤。public class HomeFragment extends Fragment { private static final String TAG = "HomeFragment"; private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION; private static final String COARSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION; //vars private Boolean mLocationPermissionsGranted = false; private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234; private GoogleMap mMap; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {  return inflater.inflate(R.layout.layout_home, container, false);  getLocationPermision(); } private void initMap() {  SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);  mapFragment.getMapAsync(new OnMapReadyCallback() {   @Override   public void onMapReady(GoogleMap googleMap) {    mMap = googleMap;   }  }); } private void getLocationPermision() {  String[] permissions = {   Manifest.permission.ACCESS_FINE_LOCATION,   Manifest.permission.ACCESS_COARSE_LOCATION  };  if (ContextCompat.checkSelfPermission(this.getActivity().getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {   if (ContextCompat.checkSelfPermission(this.getActivity().getApplicationContext(), COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {    mLocationPermissionsGranted = true;   }  } else {   ActivityCompat.requestPermissions(this.getActivity(), permissions, LOCATION_PERMISSION_REQUEST_CODE);  } }當我嘗試打電話時getLocationPermission()它讓我你能幫我一下嗎?我應該在主要活動中進行這些權限驗證嗎?在主要活動中,我只有一個導航欄,當然我想處理片段。
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

@Nullable

@Override

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    return inflater.inflate(R.layout.layout_home,container,false);


    getLocationPermision();

}

getLocationPermision();在您的 return 語句之后調用。使其無法到達。


將其移至 return 語句之前。


查看完整回答
反對 回復 2023-10-12
  • 1 回答
  • 0 關注
  • 94 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號