when i first load my app mapActivity is invoking and i can see the map, now when i
switch off the networkconnectivity and on again , changing the screen and coming back
to the mapactivity the map is showing null, getting nullpointer exception at this
line new MapUtils().drawMap(this);
in onResume()
method.
@Override
protected void onResume() {
Utils utils = new Utils();
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);
super.onResume();
Log.d(TAG, "Constants.isDataLoadedPAB " + Constants.isMaptobeLoaded
+ " Constants.isDataLoadedPAB : " + Constants.isDataLoadedPAB);
if (Constants.isMaptobeLoaded) {
if (Constants.isDataLoadedPAB) {
try {
new MapUtils().drawMap(this);
} catch (Exception e) {
Log.e(TAG, "Error", e);
}
} else {
if (Constants.currentLocation != null
&& Constants.searchLocation != null) {
if (Constants.searchResultData == null) {
Constants.searchResultData = new ArrayList<AttractionData>();
}
new MapUtils().drawMap(this);
}
}
}
((ImageView) activity.findViewById(R.id.left)).setEnabled(true);
((ImageView) activity.findViewById(R.id.right)).setEnabled(true);
((ImageView) findViewById(R.id.searchicon)).setEnabled(true);
((ImageView) activity.findViewById(R.id.facebookintegration)).setEnabled(true);
}
I am trying to invoke it again in onResume()
but still getting null.
i am struck not sure where i am doing wrong.Any help is appreciated
my log
01-29 11:23:36.325: E/AndroidRuntime(6668): Caused by: java.lang.NullPointerException
01-29 11:23:36.325: E/AndroidRuntime(6668): at org.appright.myneighborhood.maps.MapUtils.drawMap(MapUtils.java:59)
01-29 11:23:36.325: E/AndroidRuntime(6668): at org.appright.myneighborhood.activity.CityAttractions.onResume(CityAttractions.java:505)
01-29 11:23:36.325: E/AndroidRuntime(6668): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1199)
01-29 11:23:36.325: E/AndroidRuntime(6668): at android.app.Activity.performResume(Activity.java:5280)
01-29 11:23:36.325: E/AndroidRuntime(6668): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2606)
01-29 11:23:36.325: E/AndroidRuntime(6668): ... 10 more
The problem is with this line
FrameLayout topLayout = (FrameLayout) activity.findViewById(R.id.map_container);
topLayout.removeAllViews();
in MapUtils().drawMap(this);
what you are doing is to remove all the view from container i.e. FrameLayout map_container
when network connection
not available.
And when network comes again you are accessing the MapView
which you have removed from the layout hierarchy and it wont find the defaultmapView
this time and throw NullPionterException
.
Try to comment all the code in else
block and just show a toast only. hope it will work. Or try some different logic.