jason flanagan
jason flanagan

Reputation: 117

how to pass a changing variable to another class useing .putExtra()

I am trying to pass a int called Money to another class but it keeps telling me "Cannot make a static reference to the non-static method putExtra(String, int) from the type Intent"

int Money = 0;

GoToSettings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
                Intent intent = new Intent(getApplicationContext(), settings.class);
                Intent.putExtra("Money",Money);
                //^^^^^that's the variable i am trying to use
                startActivity(intent);

        }

    });

"Money" constantly changes and I don't know how else to get it to go to my second class.

PS I am still trying to learn how to use this site so please bear with me if I didn't do something right.

Upvotes: 0

Views: 75

Answers (1)

TheLostMind
TheLostMind

Reputation: 36304

Change Intent.putExtra("Money",Money); to intent.putExtra("Money",Money); Intent is a class, intent is an instance of Intent, and putExtra() is an instance level method so you have to call it using intent

Upvotes: 4

Related Questions