0

当我启动应用程序时,地图加载正常。现在我停止了网络连接,滑动了几个屏幕并再次启动了网络连接。现在,当我滑动屏幕时,我得到了 NullPointerException。调用 onResume 时地图无法加载。

在 onCreate 我正在这样做

@Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.cityattractions);
        Utils utils = new Utils();
        if (getIntent() != null && getIntent().getBooleanExtra("EXIT", false)) {
             finish();


            if(utils.getUserAcceptance(this)){
            utils.cleanUpSession();
            activity = this;
            context = this;
            Log.d(TAG, "onCreate");
            utils.loadStartUpInfo(this);
            Intent intent = getIntent();
            Bundle b = intent.getExtras();
            String moduleName = null;

            MapView mapView = (MapView) activity.findViewById(R.id.defaultmapView);
            mapView.setVisibility(View.GONE);

            if (b != null) {
                moduleName = b.getString("neighborhood");
            }

            MenuUtils menuUtils = new MenuUtils();
            ((ImageView) findViewById(R.id.custom_menu)).setOnTouchListener(new OpenPopup(this));
            if (moduleName != null && moduleName.equalsIgnoreCase("myneighbor")) {

                setMyNeighborHoodLocation();
                new Utils().loadCityNames(activity, -1, -1, -1, null, 0, true);
                new MapUtils().drawMap(this);
            } else {

                manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                listener = new ManageLocation();    
                listener.setSucessCallBack(this, "setLocation");
                listener.setFailureCallBack(this, "setNoLocation");

                manager.requestLocationUpdates(
                        utils.getCurrentPlaceLocationProvider(manager), 0, 0,
                        listener);

在 onResume 我正在做如下

protected void onResume() {

        super.onResume();

        Utils utils = new Utils();
        if (new Utils().isConnectionAvailable(activity)) {  
        manager.requestLocationUpdates(
                utils.getCurrentPlaceLocationProvider(manager), 0, 0,
                listener); }

                    new MapUtils().drawMap(this);
                }

我尝试在 onPause() 方法中取消注册 LocationListener。但似乎没有任何效果。有人可以指出我正确的方向吗?

这是我的日志猫

 Caused by: java.lang.NullPointerException
01-28 18:41:02.013: E/AndroidRuntime(32082):    at org.appright.mycity.maps.MapUtils.drawMap(MapUtils.java:59)
01-28 18:41:02.013: E/AndroidRuntime(32082):    at org.appright.mycity.activity.CityAttractions.onResume(CityAttractions.java:500)
01-28 18:41:02.013: E/AndroidRuntime(32082):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1199)
01-28 18:41:02.013: E/AndroidRuntime(32082):    at android.app.Activity.performResume(Activity.java:5280)
01-28 18:41:02.013: E/AndroidRuntime(32082):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2606)
01-28 18:41:02.013: E/AndroidRuntime(32082):    ... 10 more
4

0 回答 0