0

我开发了简单的应用程序来显示 android 中的纬度和经度......但它显示空指针异常......请让我知道错误是什么......

我的活动课

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;


public class SignalStrengthActivity extends Activity implements LocationListener{

    private LocationManager  locationManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    }


    @Override
    protected void onResume() {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this);
        super.onResume();
    }

    @Override
    protected void onPause() {
        locationManager.removeUpdates(this);
        super.onPause();
    }


    @Override
    public void onLocationChanged(Location location) {
         if (location != null) {
                Toast.makeText(this, "Latitude and Longitude " + location.getLatitude() + " " + 
                        location.getLongitude(), Toast.LENGTH_SHORT).show();
            }

    }

    @Override
    public void onProviderDisabled(String provider) {

         Toast.makeText(this, "Latitude and Longitude Offline ", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onProviderEnabled(String provider) {


    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {


    }
}

我的清单文件:-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.latitudelongitude"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.latitudelongitude.SignalStrengthActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

当我执行应用程序时,它不显示任何内容..表明位置对象为空...请让我知道如何解决问题

4

1 回答 1

0

浏览以下链接:

链接 1

于 2013-03-26T11:37:17.507 回答