Jasma
Jasma

Reputation: 133

Android: Error while passing int from one activity to another

I am reading my DB in Activity A - Fetching String, int, String. I am passing this to Activity B and want to display it in 3 Text fields The String values get displayed properly, but the int gives me this error

01-03 15:39:48.252: E/ERROR(980): android.content.res.Resources$NotFoundException: String resource ID #0x1f4

My code

Activity A

Intent myintent2 = new Intent(MoneySummaryPage.this,EnterBankDetails.class);
myintent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
myintent2.putExtra("bank", updateBank);
myintent2.putExtra("amount", updateAmt);
myintent2.putExtra("Currency", updateCur);
myintent2.putExtra("constant", "1");
startActivity(myintent2);

Activity B

    BankName =      (EditText)findViewById(R.id.bankNameLabel);
    BalanceAmount = (EditText)findViewById(R.id.balanceLabel);
    currencySpin = (Spinner)findViewById(R.id.currencySpinner);

    constantpass = getIntent().getExtras().getString("constant");

    BankName.setText(getIntent().getExtras().getString("bank"));
    BalanceAmount.setText(getIntent().getIntExtra("amount", 0));

The BalanceAmount is the Integer field and I am getting blank values there. Also, my third String is to be populated in the Spinner? Can someone tell me the code for populating that?

Thanks!

Upvotes: 2

Views: 279

Answers (3)

Asanka Senavirathna
Asanka Senavirathna

Reputation: 4730

The TextView value should be a String, not an int.

this is the the proper way to do this:

int iAmount = getIntent().getIntExtra("amount", 0); BalanceAmount.setText(String.valueOf(iAmount));

Upvotes: 2

andre
andre

Reputation: 1728

To update your Spinner use the View.invalidate() method.

Or the Adapter.notifyDatasetChanged() Method

Upvotes: 0

Andro Selva
Andro Selva

Reputation: 54322

Try this,

 BalanceAmount.setText(getIntent().getIntExtra("amount", 0)+"");

The problem is , when you try to provide a int value to setText(), the system looks for the resource file with that int id. It might not understand the difference between a int value and a int res(R.String.someValue is considered as int in android).

Now with the above piece of code, the int is now converted to String and hence you will not have any problem and of course you are reducing two lines of code to one.

Upvotes: 6

Related Questions