How to pass an int data with an intent?












-1















Hi I'm doing a project and I'm using room persistence to manage my database but when I get the id from my activity to pass it to another activity for edit the data it gives that incompatible types



Here is my DaoClass, I want to call getOne methos



 @Insert
void insert(Entradas entradas);

@Update
void update(Entradas entradas);

@Delete
void delete(Entradas entradas);

@Query("DELETE FROM Entradas")
void deleteAll();

@Query("SELECT * FROM Entradas")
LiveData<List<Entradas>> getAll();

@Query("SELECT * FROM Entradas WHERE IdEntrada ==:Id")
LiveData<Entradas> getOne(int Id);


Here is my activity, when I'm using the methos longClickListener to sent me to another activity



        adapter.addActionCallback(new EntradasAdapter.ActionCallback() {
@Override
public void onLongClickListener(Entradas entradas) {
Intent intent = new Intent(getActivity(), UpdateEntradaActivity.class);
intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID, entradas.getIdEntrada());
startActivity(intent);
}
});


And this the activity that I want to show the data



public static String EXTRA_ENTRADA_ID = "IdEntrada";

private Button btnCalendario, btnCrear;
private EditText etNombre, etSaldo;
private TextView etFecha;
Calendar c;
DatePickerDialog dpd;
private CategoriaEntradasViewModel viewModel;
private CuentasViewModel viewModel1;
private EntradasViewModel viewModel2;
Spinner spinner, spinner1;
List<CategoriaEntradas> categoriaEntradas1;
List<Cuentas> cuentas1;
private EntradasDao mEntradasDAO;
private Entradas ENTRADAS;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_entrada);

getSupportActionBar().setTitle(Html.fromHtml("<font color='#FFFFFF'>"+"Editar Entrada"+"</font>"));
getSupportActionBar().setElevation(0);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

mEntradasDAO = Room.databaseBuilder(this, Database.class, "Database")
.allowMainThreadQueries() //Allows room to do operation on main thread
.build()
.entradasDao();

final Context ctx = this;
etNombre= findViewById(R.id.editText);
etSaldo= findViewById(R.id.editText4);
etFecha = (TextView) findViewById(R.id.txtFecha);
btnCalendario= (Button) findViewById(R.id.btnFecha);
btnCrear = findViewById(R.id.btnCrear);



ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
}


The error is in the last line ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



it says getOne(int) in EntradasDao cannot be applied to java.lang.String










share|improve this question





























    -1















    Hi I'm doing a project and I'm using room persistence to manage my database but when I get the id from my activity to pass it to another activity for edit the data it gives that incompatible types



    Here is my DaoClass, I want to call getOne methos



     @Insert
    void insert(Entradas entradas);

    @Update
    void update(Entradas entradas);

    @Delete
    void delete(Entradas entradas);

    @Query("DELETE FROM Entradas")
    void deleteAll();

    @Query("SELECT * FROM Entradas")
    LiveData<List<Entradas>> getAll();

    @Query("SELECT * FROM Entradas WHERE IdEntrada ==:Id")
    LiveData<Entradas> getOne(int Id);


    Here is my activity, when I'm using the methos longClickListener to sent me to another activity



            adapter.addActionCallback(new EntradasAdapter.ActionCallback() {
    @Override
    public void onLongClickListener(Entradas entradas) {
    Intent intent = new Intent(getActivity(), UpdateEntradaActivity.class);
    intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID, entradas.getIdEntrada());
    startActivity(intent);
    }
    });


    And this the activity that I want to show the data



    public static String EXTRA_ENTRADA_ID = "IdEntrada";

    private Button btnCalendario, btnCrear;
    private EditText etNombre, etSaldo;
    private TextView etFecha;
    Calendar c;
    DatePickerDialog dpd;
    private CategoriaEntradasViewModel viewModel;
    private CuentasViewModel viewModel1;
    private EntradasViewModel viewModel2;
    Spinner spinner, spinner1;
    List<CategoriaEntradas> categoriaEntradas1;
    List<Cuentas> cuentas1;
    private EntradasDao mEntradasDAO;
    private Entradas ENTRADAS;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_update_entrada);

    getSupportActionBar().setTitle(Html.fromHtml("<font color='#FFFFFF'>"+"Editar Entrada"+"</font>"));
    getSupportActionBar().setElevation(0);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    mEntradasDAO = Room.databaseBuilder(this, Database.class, "Database")
    .allowMainThreadQueries() //Allows room to do operation on main thread
    .build()
    .entradasDao();

    final Context ctx = this;
    etNombre= findViewById(R.id.editText);
    etSaldo= findViewById(R.id.editText4);
    etFecha = (TextView) findViewById(R.id.txtFecha);
    btnCalendario= (Button) findViewById(R.id.btnFecha);
    btnCrear = findViewById(R.id.btnCrear);



    ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
    }


    The error is in the last line ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



    it says getOne(int) in EntradasDao cannot be applied to java.lang.String










    share|improve this question



























      -1












      -1








      -1








      Hi I'm doing a project and I'm using room persistence to manage my database but when I get the id from my activity to pass it to another activity for edit the data it gives that incompatible types



      Here is my DaoClass, I want to call getOne methos



       @Insert
      void insert(Entradas entradas);

      @Update
      void update(Entradas entradas);

      @Delete
      void delete(Entradas entradas);

      @Query("DELETE FROM Entradas")
      void deleteAll();

      @Query("SELECT * FROM Entradas")
      LiveData<List<Entradas>> getAll();

      @Query("SELECT * FROM Entradas WHERE IdEntrada ==:Id")
      LiveData<Entradas> getOne(int Id);


      Here is my activity, when I'm using the methos longClickListener to sent me to another activity



              adapter.addActionCallback(new EntradasAdapter.ActionCallback() {
      @Override
      public void onLongClickListener(Entradas entradas) {
      Intent intent = new Intent(getActivity(), UpdateEntradaActivity.class);
      intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID, entradas.getIdEntrada());
      startActivity(intent);
      }
      });


      And this the activity that I want to show the data



      public static String EXTRA_ENTRADA_ID = "IdEntrada";

      private Button btnCalendario, btnCrear;
      private EditText etNombre, etSaldo;
      private TextView etFecha;
      Calendar c;
      DatePickerDialog dpd;
      private CategoriaEntradasViewModel viewModel;
      private CuentasViewModel viewModel1;
      private EntradasViewModel viewModel2;
      Spinner spinner, spinner1;
      List<CategoriaEntradas> categoriaEntradas1;
      List<Cuentas> cuentas1;
      private EntradasDao mEntradasDAO;
      private Entradas ENTRADAS;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_update_entrada);

      getSupportActionBar().setTitle(Html.fromHtml("<font color='#FFFFFF'>"+"Editar Entrada"+"</font>"));
      getSupportActionBar().setElevation(0);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setDisplayShowHomeEnabled(true);

      mEntradasDAO = Room.databaseBuilder(this, Database.class, "Database")
      .allowMainThreadQueries() //Allows room to do operation on main thread
      .build()
      .entradasDao();

      final Context ctx = this;
      etNombre= findViewById(R.id.editText);
      etSaldo= findViewById(R.id.editText4);
      etFecha = (TextView) findViewById(R.id.txtFecha);
      btnCalendario= (Button) findViewById(R.id.btnFecha);
      btnCrear = findViewById(R.id.btnCrear);



      ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
      }


      The error is in the last line ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



      it says getOne(int) in EntradasDao cannot be applied to java.lang.String










      share|improve this question
















      Hi I'm doing a project and I'm using room persistence to manage my database but when I get the id from my activity to pass it to another activity for edit the data it gives that incompatible types



      Here is my DaoClass, I want to call getOne methos



       @Insert
      void insert(Entradas entradas);

      @Update
      void update(Entradas entradas);

      @Delete
      void delete(Entradas entradas);

      @Query("DELETE FROM Entradas")
      void deleteAll();

      @Query("SELECT * FROM Entradas")
      LiveData<List<Entradas>> getAll();

      @Query("SELECT * FROM Entradas WHERE IdEntrada ==:Id")
      LiveData<Entradas> getOne(int Id);


      Here is my activity, when I'm using the methos longClickListener to sent me to another activity



              adapter.addActionCallback(new EntradasAdapter.ActionCallback() {
      @Override
      public void onLongClickListener(Entradas entradas) {
      Intent intent = new Intent(getActivity(), UpdateEntradaActivity.class);
      intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID, entradas.getIdEntrada());
      startActivity(intent);
      }
      });


      And this the activity that I want to show the data



      public static String EXTRA_ENTRADA_ID = "IdEntrada";

      private Button btnCalendario, btnCrear;
      private EditText etNombre, etSaldo;
      private TextView etFecha;
      Calendar c;
      DatePickerDialog dpd;
      private CategoriaEntradasViewModel viewModel;
      private CuentasViewModel viewModel1;
      private EntradasViewModel viewModel2;
      Spinner spinner, spinner1;
      List<CategoriaEntradas> categoriaEntradas1;
      List<Cuentas> cuentas1;
      private EntradasDao mEntradasDAO;
      private Entradas ENTRADAS;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_update_entrada);

      getSupportActionBar().setTitle(Html.fromHtml("<font color='#FFFFFF'>"+"Editar Entrada"+"</font>"));
      getSupportActionBar().setElevation(0);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setDisplayShowHomeEnabled(true);

      mEntradasDAO = Room.databaseBuilder(this, Database.class, "Database")
      .allowMainThreadQueries() //Allows room to do operation on main thread
      .build()
      .entradasDao();

      final Context ctx = this;
      etNombre= findViewById(R.id.editText);
      etSaldo= findViewById(R.id.editText4);
      etFecha = (TextView) findViewById(R.id.txtFecha);
      btnCalendario= (Button) findViewById(R.id.btnFecha);
      btnCrear = findViewById(R.id.btnCrear);



      ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
      }


      The error is in the last line ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



      it says getOne(int) in EntradasDao cannot be applied to java.lang.String







      android android-room






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 16:28









      Fantômas

      32.4k156388




      32.4k156388










      asked Nov 19 '18 at 16:18









      Eduardo NoyolaEduardo Noyola

      455




      455
























          2 Answers
          2






          active

          oldest

          votes


















          2














          You are putting as Int and while reading trying get as String.
          Replace



              mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
          with
          mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID,0));





          share|improve this answer
























          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:05





















          0














          The way to read that message is "the method getOne() accepts an int, but you are passing a java.lang.String". So you have to figure out why the value you're passing is a String.




          ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



          In your case, though, this is pretty straightforward. You are passing it the value of a getStringExtra() call, which is always going to be a String.



          There are two paths forward to fixing this. Which you choose will depend on whether or not the value you're putting into the Intent is actually a String or an int.




          intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID,  entradas.getIdEntrada());



          If entradas.getIdEntrada() is an int, then you can change the other side of things to simply retrieve an int extra:



          ENTRADAS = mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0));


          If entradas.getIdEntrada() is a String, then you will have to change the other side to retrieve the String and then parse it to an int



          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt);


          Edit



          As mentioned in comments, the return value of the getOne() method is a LiveData<Entradas>, not just an Entradas. While this is not the recommended way to use LiveData, for the purposes of this question you can retrieve the value by calling getValue().



          int idInt = getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();




          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();





          share|improve this answer


























          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:10











          • How a LiveData object works is outside the scope of this question, but you can get the current value of the LiveData by calling getValue(). So you can say ENTRADAS = mEntradasDAO.getOne(idInt).getValue();

            – Ben P.
            Nov 19 '18 at 17:14











          • Thanks but now I'm getting null in the other activity

            – Eduardo Noyola
            Nov 19 '18 at 20:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378757%2fhow-to-pass-an-int-data-with-an-intent%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You are putting as Int and while reading trying get as String.
          Replace



              mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
          with
          mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID,0));





          share|improve this answer
























          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:05


















          2














          You are putting as Int and while reading trying get as String.
          Replace



              mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
          with
          mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID,0));





          share|improve this answer
























          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:05
















          2












          2








          2







          You are putting as Int and while reading trying get as String.
          Replace



              mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
          with
          mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID,0));





          share|improve this answer













          You are putting as Int and while reading trying get as String.
          Replace



              mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));
          with
          mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID,0));






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 16:33









          Ramesh YankatiRamesh Yankati

          65848




          65848













          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:05





















          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:05



















          Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

          – Eduardo Noyola
          Nov 19 '18 at 17:05







          Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

          – Eduardo Noyola
          Nov 19 '18 at 17:05















          0














          The way to read that message is "the method getOne() accepts an int, but you are passing a java.lang.String". So you have to figure out why the value you're passing is a String.




          ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



          In your case, though, this is pretty straightforward. You are passing it the value of a getStringExtra() call, which is always going to be a String.



          There are two paths forward to fixing this. Which you choose will depend on whether or not the value you're putting into the Intent is actually a String or an int.




          intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID,  entradas.getIdEntrada());



          If entradas.getIdEntrada() is an int, then you can change the other side of things to simply retrieve an int extra:



          ENTRADAS = mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0));


          If entradas.getIdEntrada() is a String, then you will have to change the other side to retrieve the String and then parse it to an int



          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt);


          Edit



          As mentioned in comments, the return value of the getOne() method is a LiveData<Entradas>, not just an Entradas. While this is not the recommended way to use LiveData, for the purposes of this question you can retrieve the value by calling getValue().



          int idInt = getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();




          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();





          share|improve this answer


























          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:10











          • How a LiveData object works is outside the scope of this question, but you can get the current value of the LiveData by calling getValue(). So you can say ENTRADAS = mEntradasDAO.getOne(idInt).getValue();

            – Ben P.
            Nov 19 '18 at 17:14











          • Thanks but now I'm getting null in the other activity

            – Eduardo Noyola
            Nov 19 '18 at 20:06
















          0














          The way to read that message is "the method getOne() accepts an int, but you are passing a java.lang.String". So you have to figure out why the value you're passing is a String.




          ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



          In your case, though, this is pretty straightforward. You are passing it the value of a getStringExtra() call, which is always going to be a String.



          There are two paths forward to fixing this. Which you choose will depend on whether or not the value you're putting into the Intent is actually a String or an int.




          intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID,  entradas.getIdEntrada());



          If entradas.getIdEntrada() is an int, then you can change the other side of things to simply retrieve an int extra:



          ENTRADAS = mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0));


          If entradas.getIdEntrada() is a String, then you will have to change the other side to retrieve the String and then parse it to an int



          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt);


          Edit



          As mentioned in comments, the return value of the getOne() method is a LiveData<Entradas>, not just an Entradas. While this is not the recommended way to use LiveData, for the purposes of this question you can retrieve the value by calling getValue().



          int idInt = getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();




          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();





          share|improve this answer


























          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:10











          • How a LiveData object works is outside the scope of this question, but you can get the current value of the LiveData by calling getValue(). So you can say ENTRADAS = mEntradasDAO.getOne(idInt).getValue();

            – Ben P.
            Nov 19 '18 at 17:14











          • Thanks but now I'm getting null in the other activity

            – Eduardo Noyola
            Nov 19 '18 at 20:06














          0












          0








          0







          The way to read that message is "the method getOne() accepts an int, but you are passing a java.lang.String". So you have to figure out why the value you're passing is a String.




          ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



          In your case, though, this is pretty straightforward. You are passing it the value of a getStringExtra() call, which is always going to be a String.



          There are two paths forward to fixing this. Which you choose will depend on whether or not the value you're putting into the Intent is actually a String or an int.




          intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID,  entradas.getIdEntrada());



          If entradas.getIdEntrada() is an int, then you can change the other side of things to simply retrieve an int extra:



          ENTRADAS = mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0));


          If entradas.getIdEntrada() is a String, then you will have to change the other side to retrieve the String and then parse it to an int



          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt);


          Edit



          As mentioned in comments, the return value of the getOne() method is a LiveData<Entradas>, not just an Entradas. While this is not the recommended way to use LiveData, for the purposes of this question you can retrieve the value by calling getValue().



          int idInt = getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();




          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();





          share|improve this answer















          The way to read that message is "the method getOne() accepts an int, but you are passing a java.lang.String". So you have to figure out why the value you're passing is a String.




          ENTRADAS = mEntradasDAO.getOne(getIntent().getStringExtra(EXTRA_ENTRADA_ID));



          In your case, though, this is pretty straightforward. You are passing it the value of a getStringExtra() call, which is always going to be a String.



          There are two paths forward to fixing this. Which you choose will depend on whether or not the value you're putting into the Intent is actually a String or an int.




          intent.putExtra(UpdateEntradaActivity.EXTRA_ENTRADA_ID,  entradas.getIdEntrada());



          If entradas.getIdEntrada() is an int, then you can change the other side of things to simply retrieve an int extra:



          ENTRADAS = mEntradasDAO.getOne(getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0));


          If entradas.getIdEntrada() is a String, then you will have to change the other side to retrieve the String and then parse it to an int



          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt);


          Edit



          As mentioned in comments, the return value of the getOne() method is a LiveData<Entradas>, not just an Entradas. While this is not the recommended way to use LiveData, for the purposes of this question you can retrieve the value by calling getValue().



          int idInt = getIntent().getIntExtra(EXTRA_ENTRADA_ID, 0);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();




          String idString = getIntent().getStringExtra(EXTRA_ENTRADA_ID);
          int idInt = Integer.parseInt(idString);
          ENTRADAS = mEntradasDAO.getOne(idInt).getValue();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '18 at 17:16

























          answered Nov 19 '18 at 16:31









          Ben P.Ben P.

          23.6k32049




          23.6k32049













          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:10











          • How a LiveData object works is outside the scope of this question, but you can get the current value of the LiveData by calling getValue(). So you can say ENTRADAS = mEntradasDAO.getOne(idInt).getValue();

            – Ben P.
            Nov 19 '18 at 17:14











          • Thanks but now I'm getting null in the other activity

            – Eduardo Noyola
            Nov 19 '18 at 20:06



















          • Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

            – Eduardo Noyola
            Nov 19 '18 at 17:10











          • How a LiveData object works is outside the scope of this question, but you can get the current value of the LiveData by calling getValue(). So you can say ENTRADAS = mEntradasDAO.getOne(idInt).getValue();

            – Ben P.
            Nov 19 '18 at 17:14











          • Thanks but now I'm getting null in the other activity

            – Eduardo Noyola
            Nov 19 '18 at 20:06

















          Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

          – Eduardo Noyola
          Nov 19 '18 at 17:10





          Now it says Incompatible types Required: Entities.Entradas Found: lifecycle.LiveData

          – Eduardo Noyola
          Nov 19 '18 at 17:10













          How a LiveData object works is outside the scope of this question, but you can get the current value of the LiveData by calling getValue(). So you can say ENTRADAS = mEntradasDAO.getOne(idInt).getValue();

          – Ben P.
          Nov 19 '18 at 17:14





          How a LiveData object works is outside the scope of this question, but you can get the current value of the LiveData by calling getValue(). So you can say ENTRADAS = mEntradasDAO.getOne(idInt).getValue();

          – Ben P.
          Nov 19 '18 at 17:14













          Thanks but now I'm getting null in the other activity

          – Eduardo Noyola
          Nov 19 '18 at 20:06





          Thanks but now I'm getting null in the other activity

          – Eduardo Noyola
          Nov 19 '18 at 20:06


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378757%2fhow-to-pass-an-int-data-with-an-intent%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?