javascript - 出现 'Cannot resolve method' 错误

标签 javascript java android variables

我在下面的代码中遇到错误。错误是“无法解析方法‘getApplication()’” 有什么帮助吗?我认为这是因为我拉动全局变量的方式。也许是设置变量的更好方法。

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");
      }


    });
  }

}

最佳答案

你的“this”指的是onClickListener

这样做:

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

这次的“这个”指的是你的 Activity 课

关于javascript - 出现 'Cannot resolve method' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31420091/

相关文章:

java - Google Endpoints API 对其他 API 的身份验证

javascript - 如何从URL收集变量,将其插入数组并动态更改href URL?

javascript - 检测node/webpack项目中的文件添加/删除

javascript - jsPDF 不适用于 IE 7/8 和 Firefox 13?

java - 在我的代码中找不到符号变量 java 错误

java - 使用小程序在客户端系统上写入文件

android - statusCode=DEVELOPER_ERROR 在谷歌登录

java - 当我在 Android 应用程序中创建图像时拍照时,会在 DCIM/Camera 中生成副本

javascript - 用单引号引起来时,正则表达式不起作用

android - Android 市场中的编程 IDE