-2

我無法在碎片中使用Google API客戶端。如何在碎片中使用GoogleAPI客戶端

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.layout_case_summary, container, false); 

     initView(rootView); 
     return rootView; 

     if(mGoogleApiClient==null) { 
      mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) 
        .addConnectionCallbacks(this) 
        .addOnConnectionFailedListener(this) 
        .addApi(LocationServices.API) 
        .build(); 
     } 
     } 

它顯示錯誤: enter image description here

+0

「無法訪問的聲明」。你沒有研究這個? –

回答

0

只需切換return語句和谷歌的API客戶端初始化:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.layout_case_summary, container, false); 

    initView(rootView); 

    if(mGoogleApiClient==null) { 
     mGoogleApiClient = new GoogleApiClient.Builder(getActivity()) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .addApi(LocationServices.API) 
       .build(); 
    } 
    return rootView; 
} 

return語句應該總是在你的方法中的最後一行。