当尝试在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);
}
)
};
}
答案 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