0

Androidで緯度と経度を表示する簡単なアプリケーションを開発しました...しかし、nullポインタ例外が表示されています...エラーを教えてください。

マイアクティビティクラス

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>

アプリケーションを実行しても何も表示されません。ロケーションオブジェクトがnullであることを示しています...問題の修正方法を教えてください

4

1 に答える 1

0

以下のリンクをご覧ください。

リンク1

于 2013-03-26T11:37:17.507 に答える