Google Map v2 inside android fragment
Asked Answered
B

1

6

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.

Block answered 19/7, 2013 at 10:37 Comment(2)
could you post your XML as well please?Alcaeus
I have solved the problem, will post the answer nowBlock
B
14

Ok so the solution was to add the following line:

super.onCreateView(inflater, container, savedInstanceState);
Block answered 19/7, 2013 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.