How to send data from an Activity to a Fragment?

Asked

Viewed 113 times

0

1I’ve been having a question for a while. I want to pass a value of a activity for a fragment, however, the error when opening the fragment to be specific when receiving this value, I believe.

This is how Seto:

estab = "academia";

        MapsFragment_Estab mapsFragment_estab = new MapsFragment_Estab();
        Bundle academia = new Bundle();
        academia.putString("CoordAcademy", estab);
        mapsFragment_estab.setArguments(academia);

And this is how I get on fragment:

String CoordAcademy = getArguments().getString("CoordAcademy");

[inserir a descrição da imagem aqui]

  • With prints, hardly anyone will help you. Instead post the code itself. See: How not to ask

  • 1

    I get it, I’m new around here. I get it, vlw =D.

  • Are you putting the String CoordAcademy = getArguments().getString("CoordAcademy"); within the method onCreateView()? Post the whole method. If possible add the error message as well.

  • Error in my map Fragment in onCreate method.

  • You would be able to post the error message that appears in your Log, at the end of the question? Because at first the syntax is correct.

  • Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null Object Reference At Fragments.Mapsfragment_estab.onCreate(Mapsfragment_estab.java:27)

  • Estou repostando o Oncreate sem os meus comments pra ficar mais limpo: public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 

 String CoordAcademy = getArguments(). getString("Coordacademy"); getMapAsync(this); }

  • I printed the mistakes, above. Already, I thank the attention.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.