I am getting nullpointer exception on map initialisation using SupportMapFragment.I have added google play lib also. It throws exception at line map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
on onStart() method.
My code is:
public class MapSectionFragment extends Fragment {
GoogleMap map;
@Override
public void onStart() {
// TODO Auto-generated method stub
super.onStart();
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
public Fragment newInstance() {
return new MapSectionFragment();
}
View rootView = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try{
if (null == savedInstanceState)
rootView = inflater.inflate(R.layout.lay_search_map, container,
false);
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
}
lay_search_map.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
tools:context=".LocatorMainActivity$DummySectionFragment" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
</RelativeLayout>
this is my error log:
11-30 14:37:13.100: E/AndroidRuntime(6159): FATAL EXCEPTION: main
11-30 14:37:13.100: E/AndroidRuntime(6159): java.lang.NullPointerException
11-30 14:37:13.100: E/AndroidRuntime(6159): at com.agile.pbc.LocatorMainActivity$MapSectionFragment.onStart(LocatorMainActivity.java:533)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.app.Fragment.performStart(Fragment.java:1524)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:957)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.View.measure(View.java:12922)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.View.measure(View.java:12922)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.View.measure(View.java:12922)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.widget.LinearLayout.measureVertical(LinearLayout.java:822)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.widget.LinearLayout.onMeasure(LinearLayout.java:563)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.View.measure(View.java:12922)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4706)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
11-30 14:37:13.100: E/AndroidRuntime(6159): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2261)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.View.measure(View.java:12922)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1255)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2649)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.os.Looper.loop(Looper.java:137)
11-30 14:37:13.100: E/AndroidRuntime(6159): at android.app.ActivityThread.main(ActivityThread.java:4507)
11-30 14:37:13.100: E/AndroidRuntime(6159): at java.lang.reflect.Method.invokeNative(Native Method)
11-30 14:37:13.100: E/AndroidRuntime(6159): at java.lang.reflect.Method.invoke(Method.java:511)
11-30 14:37:13.100: E/AndroidRuntime(6159): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
11-30 14:37:13.100: E/AndroidRuntime(6159): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
11-30 14:37:13.100: E/AndroidRuntime(6159): at dalvik.system.NativeStart.main(Native Method)
Try with MapFragment --