Google maps in android snippet

I am having problems loading google maps in my snippet. It all starts with the recycler view adapter, which launches the "ViatgeDetallViewActivity":

Context context = mActivity.getApplicationContext(); 
                    Intent intent = new Intent(context, ViatgeDetallViewActivity.class);
                   holder.mViatge.getId());
                    intent.putExtra("desc",p.getDesc());
                    intent.putExtra("location",p.getLocation());
                    mActivity.startActivityForResult(intent,ACTIVITY_View);

      

This is my DetallViewActivity:

public class ViatgeDetallViewActivity extends AppCompatActivity {

ViatgeDetallViewFragment fragment;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view);
    Bundle extras = getIntent().getExtras();
    if(extras != null)
    {

        String s =  getIntent().getStringExtra("desc");
        Location l = getIntent().getParcelableExtra("location");

        Log.d("myTag", "estoy en el oncreate de detallviewActivity pasando pro extras" + s );


    }

        fragment = new ViatgeDetallViewFragment();


        getSupportFragmentManager().beginTransaction()
                .add(R.id.activity_fragment_view, fragment)  
                .commit();
     getFragmentManager().beginTransaction().add(R.id.activity_fragment_view, fragment).commit();
    }
}

      

With my ViatgeDetallViewFragment:

public class ViatgeDetallViewFragment extends Fragment implements OnMapReadyCallback {

private GoogleMap mMap;
private Marker mMarcadorActual;

public ViatgeDetallViewFragment() {
}
....
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_view, container, false);


    SupportMapFragment mapFragment =
            (SupportMapFragment)
                    getChildFragmentManager().findFragmentById(R.id.fragment_view_map);
    mapFragment.getMapAsync(this);


    return rootView;
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;


   //ask for permissions..
        mMap.setMyLocationEnabled(true);


    LatLng sydney = new LatLng(-34, 151);
    mMarcadorActual = mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));

}

      

With layouts available, Activity_view:

<Linear ...

  <android.support.v7.widget.Toolbar
        android:id="@+id/tlbMenuView"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        />

    <FrameLayout
        android:id="@+id/activity_fragment_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

      

fragment_view:

<LinearLayout android:id="@+id/layout_fragment_view" xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
..
    <fragment
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fragment_view_map"
        class="com.google.android.gms.maps.MapFragment"></fragment>

</LinearLayout>

      

The problem comes when I try to start tje "ViatgeDetallActivity", I get this in the log:

FATAL EXCEPTION: Main Process: com.example.usuari.myapplication3, PID: 6390 java.lang.RuntimeException: Unable to start Activity ComponentInfo {com.example.usuari.myapplication3 / com.example.usuari.myapplication3.ViatgeDetallViewActivity}: java.lang .NullPointerException: Attempt to call virtual method 'void com.google.android.gms.maps.SupportMapFragment.getMapAsync (com.google.android.gms.maps.OnMapReadyCallback) "on null object reference in android.app.ActivityThread.performLaunchActivity ( ActivityThread.java:3254) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3350) at android.app.ActivityThread.access $ 1100 (ActivityThread.java:222) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1795) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:158) at android.app.ActivityThread.main (ActivityThread.java:7229) at java.lang.reflect.Method.invoke (native method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1230) at com.android. internal.os.ZygoteInit.main (ZygoteInit.java:1120) Thrown by: java.lang.NullPointerException: Attempted to call virtual method 'void com.google.android.gms.maps.SupportMapFragment.getMapAsync (com.google.android.gms. maps.OnMapReadyCallback) "by reference to null object in com.example.usuari.myapplication3.ViatgeDetallViewFragment.onCreateView (ViatgeDetallViewFragment.java:82) in android.support.v4.app.Fragment.performCreateView (Fragment.java:2074) in android.support.v4 app.FragmentManagerImpl.moveToState (FragmentManager.java:1104) at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1286) at android.support.v4.app.BackStackRecord.run (BackStackRecord.java:758) at android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1671) at android.support.v4.app.FragmentController.execPendingsupport (FragmentController. android.java:388) .v4.app.FragmentActivity.onStart (FragmentActivity.java:619) at android.app.Instrumentation.callActivityOnStart (Instrumentation.java:1265) at android.app.Activity.performStart (Activity.java:6915) at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3217) at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3350) at android.app.ActivityThread.access $ 1100 (ActivityThread.java:222) in android .app.ActivityThread $ H.handleMessage (ActivityThread.java:1795) on android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:158) at android.app.ActivityThread.main (ActivityThread.java:7229) at java.lang.reflect.Method.invoke (native method) at com.android .internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120) 03-24 02: 55: 53.871 6390-7362 / com. example.usuari.myapplication3 W / DynamiteModule:the local module descriptor class for com.google.android.gms.googlecertificates was not found. 03-24 02: 55: 53.881 6390-7362 / com.example.usuari.myapplication3 I / DynamiteModule: given local module com.google.android.gms.googlecertificates: 0 and remote module com.google.android.gms.googlecertificates : 2 03-24 02: 55: 53.881 6390-7362 / com.example.usuari.myapplication3 I / DynamiteModule: Selected remote version com.google.android.gms.googlecertificates versiongoogle.android.gms.googlecertificates, versiongoogle.android.gms.googlecertificates, version

= 2 03-24 02: 55: 53.881 6390-7362 / com.example.usuari.myapplication3 W / ResourcesManager: getTopLevelResources: / data / user / 0 / com.google.android.gms / app_chimera / m / 00000005 / DynamiteModulesA_GmsCore_prodmnc_alldpi apk /1.0 works in com.example.usuari.myapplication3 rsrc package com.example.usuari.myapplication3 03-24 02: 55: 53.891 6390-7362 / com.example.usuari.myapplication3 D / ResourcesManager: for user 0 new overlays Null 03-24 02: 55: 53.891 6390-7362 / com.example.usuari.myapplication3 W / ResourcesManager: getTopLevelResources: / data / user / 0 / com.google.android.gms / app_chimera / m / 00000005 / DynamiteModulesA_GmsCore_prodmnc_alldpi /1.0 works in com.example.usuari.myapplication3 rsrc package com.example.usuari.myapplication3

+3


source to share


2 answers


Yours mapFragment

is null. Try the following:



@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
 super.onViewCreated(view, savedInstanceState);
MapFragment mapFragment = (MapFragment) getActivity().getFragmentManager().findFragmentById(R.id.fragment_view_map);
}

      

+5


source


Latest Google update for Maps, only MapView is supported for slices.



See here for details

+1


source







All Articles