简体   繁体   中英

Getting a 'Cannot resolve method' error

I am getting an error in the code below. The error is 'Cannot resolve method 'getApplication()' ' Any help? I think it is because of the way I am pulling my global variable. Maybe a better way to set the variable.

 public class game_select extends Activity { protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.game_select); final Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click Toast.makeText(getApplicationContext(), "Your Message", Toast.LENGTH_LONG).show(); ((Global_variables) this.getApplication()).setGameselected("http://vector-runner-remix.tresensa.com/index.html?dst=B0000"); } }); } } 

Your "this" refers to the onClickListener

Do this:

((Global_variables) game_select.this.getApplication()).setGameselected("http://vector-runner-remix.tresensa.com/index.html?dst=B0000");

The "this" this time refers to your activity class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM