Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Map v2 inside android fragment

I have the following code:

public class Tab_Map extends SupportMapFragment {

View view;
SupportMapFragment gmap;
GoogleMap map;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    view = inflater.inflate(R.layout.tab_map, container, false);

     map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.fragment1))
                .getMap();
    return view;
}

When I run my application and try and load the map tab I am getting the following error:

E/AndroidRuntime(22627): FATAL EXCEPTION: main
E/AndroidRuntime(22627): java.lang.NullPointerException
E/AndroidRuntime(22627):    at maps.ah.bg.b(Unknown Source)
E/AndroidRuntime(22627):    at bgl.onTransact(SourceFile:115)
E/AndroidRuntime(22627):    at android.os.Binder.transact(Binder.java:310)
E/AndroidRuntime(22627):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onResume(Unknown Source)
E/AndroidRuntime(22627):    at com.google.android.gms.maps.SupportMapFragment$a.onResume(Unknown Source)
E/AndroidRuntime(22627):    at com.google.android.gms.internal.bb$6.b(Unknown Source)
E/AndroidRuntime(22627):    at com.google.android.gms.internal.bb.a(Unknown Source)
E/AndroidRuntime(22627):    at com.google.android.gms.internal.bb.onResume(Unknown Source)
E/AndroidRuntime(22627):    at com.google.android.gms.maps.SupportMapFragment.onResume(Unknown Source)
E/AndroidRuntime(22627):    at android.support.v4.app.Fragment.performResume(Fragment.java:1503)
E/AndroidRuntime(22627):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
E/AndroidRuntime(22627):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
E/AndroidRuntime(22627):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
E/AndroidRuntime(22627):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
E/AndroidRuntime(22627):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
E/AndroidRuntime(22627):    at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime(22627):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(22627):    at android.os.Looper.loop(Looper.java:158)
E/AndroidRuntime(22627):    at android.app.ActivityThread.main(ActivityThread.java:5777)
E/AndroidRuntime(22627):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(22627):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(22627):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1083)
E/AndroidRuntime(22627):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
E/AndroidRuntime(22627):    at dalvik.system.NativeStart.main(Native Method)

I can't find a solution to this problem, all I am trying to do is place a map inside a child fragment.

Can someone help please.

like image 870
Phil Andrews Avatar asked Jul 19 '13 10:07

Phil Andrews


1 Answers

Ok so the solution was to add the following line:

super.onCreateView(inflater, container, savedInstanceState);
like image 57
Phil Andrews Avatar answered Oct 15 '22 03:10

Phil Andrews