main_activity java文件的错误消息

时间:2018-08-20 19:29:19

标签: java android-button

当尝试在android中构建应用程序时,我收到与main_activity.java文件有关的;的错误消息;或)或},但我不明白为什么。有人可以帮忙吗?

public class MainActivity extends AppCompatActivity {
  private Button mButton;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mButton = (Button) findViewById(R.id.button_quiz);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          //open url using Intent
          String url = "http://www.cancunsteve.com/capecod/mobilepopquiz2.htm";
          Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
          startActivity(intent);

        }
      )
    };
  }

1 个答案:

答案 0 :(得分:0)

下面是一个有效的示例,您的Button的onClickListener被错误地关闭了。

public class MainActivity extends AppCompatActivity {
  private Button mButton;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mButton = (Button) findViewById(R.id.button_quiz);
    mButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          //open url using Intent
          String url = "http://www.cancunsteve.com/capecod/mobilepopquiz2.htm";
          Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
          startActivity(intent);

        } //close OnClick
      }); //close onClickListener
    } //close onCreate
  } //close Main