小编Reh*_*han的帖子

例外:尝试在空对象引用上调用虚拟方法'int com.google.android.gms.location.LocationRequest.b()'

我已经阅读了一些相关主题但未能解决我的问题.由于我处于学习阶段,我正在尝试实施Google的位置服务教程.麻烦的是,我没有在代码中的任何地方使用"LocationRequest.b()"但是当我按下"开始更新"按钮时出现以下错误.该应用程序随后崩溃.请让我知道我做错了什么.

错误:

Exception: Attempt to invoke virtual method 'int com.google.android.gms.location.LocationRequest.b()' on a null object reference
Run Code Online (Sandbox Code Playgroud)

弹出错误的Sepcific代码位置:

protected void startLocationUpdates() {
            LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,mLocationRequest,mListener);
 }
Run Code Online (Sandbox Code Playgroud)

MainActivity.java的完整代码:

public class MainActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener {
    protected GoogleApiClient mGoogleApiClient;

    /**
     * Represents a geographical location.
     */
    protected Location mCurrentLocation;
    protected LocationRequest mLocationRequest;
    protected static final String TAG = "basic-location-sample";

    //UI Widgets
    protected Button mStartUpdatesButton;
    protected Button mStopUpdatesButton;
    protected TextView mLastUpdateTimeTextView;
    protected TextView mLatitudeTextView;
    protected TextView mLongitudeTextView;


    boolean mRequestingLocationUpdates;
    protected String mLastUpdateTime;

    // keys
    protected …
Run Code Online (Sandbox Code Playgroud)

java android google-play-services

3
推荐指数
1
解决办法
8961
查看次数

标签 统计

android ×1

google-play-services ×1

java ×1