2016-09-19 24 views
-1

我收到這個錯誤「無法解決方法requestLocationUpdates」。我不知道該怎麼做,因爲我正在使用片段,所以我已經將「this」更改爲「getActivity」。我在LocationManager中得到了這個錯誤

順便說一句,這段代碼工作時,我試圖從一個不同的項目,但它不是在一個片段。我試圖在一個片段中做到這一點,這是我的錯誤。

這裏是我的代碼:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View view = inflater.inflate(R.layout.fragment_recipients, container, false); 

    LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); 
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, getActivity()); 

    button = (Button) view.findViewById(R.id.button2); 
    button.setOnClickListener(new View.OnClickListener(){ 

     @Override 
     public void onClick(View v) { 

      String uri = "http://maps.google.com/?q="+latitude +","+longitude; 
      StringBuffer smsBody = new StringBuffer(); 

      smsBody.append(Uri.parse(uri)); 
      String msg = (" Hello, Timothy. You are at" + " " + longitude + " " + latitude).toString(); 

      try { 

       SmsManager smsManager = SmsManager.getDefault(); 
       smsManager.sendTextMessage(phoneNo, null, smsBody.toString(), null, null); 



       Toast.makeText(getContext(), "Message Sent", 
         Toast.LENGTH_LONG).show(); 
      } catch (Exception ex) { 
       Toast.makeText(getContext(), 
         ex.getMessage().toString(), 
         Toast.LENGTH_LONG).show(); 
       ex.printStackTrace(); 
      } 



     } 
    }); 
    return view; 
} 

這裏是我的進口:

import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.net.Uri; 
import android.os.Bundle; 
import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.view.Menu; 
import android.telephony.SmsManager; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.Toast; 

提前感謝!

+0

您正在使用acOutputReport,但指定了查詢名稱。當您使用acOutputReport時,您需要提供報告名稱。您似乎想要使用acOutputQuery,或者創建基於查詢的新報告,然後使用acOutputReport,「NewReportName」。有關詳細信息,請參閱[Microsoft頁面](https://msdn.microsoft.com/en-us/library/office/ff192065.aspx)。 –

回答

0

您正在使用acOutputReport,但指定了查詢名稱。當您使用acOutputReport時,您需要提供報告名稱。您似乎想要使用acOutputQuery,或者創建基於查詢的新報告,然後使用acOutputReport,「NewReportName」。

查看Microsoft's page on the OutputTo method瞭解更多信息。