【发布时间】:2017-06-13 15:43:47
【问题描述】:
我正在尝试使用 android studio 构建登录活动。他们的错误不断出现,我不知道该怎么办。我已经使用了 },但最后一个 } 仍然带有红色下划线。
这是第一次发生。
package co5025.example.com.noughtandcrosses;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button butLogin;
public boolean checkPassword() {
TextView edit_password = null;
TextView edit_username = null;
TextView butLogin;
if (edit_username.getText().toString().equals("test") &&
(edit_password.getText().toString().equals("1234")))
return true;
else
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Locate the button in activity_main.xml
Button butLogin = (Button) findViewById(R.id.butLogin);
// Capture button clicks
butLogin.setOnClickListener(new DialogInterface.OnClickListener() {
public void onClick(View arg0) {
Intent intent = getIntent();
String value = intent.getStringExtra("key"); //if it's a string you stored.
}
public void onClick(View v) {
if (checkPassword()) {
//Succeed: Load GameActivity.
Intent myIntent = new Intent(MainActivity.this,
GameActivity.class);
startActivity(myIntent);
} else {
//Fail: display error message.
AlertDialog alertDialog = null;
alertDialog.setMessage("Alert message to be shown");
}
}
} //here is the error
【问题讨论】:
-
正确缩进你的代码。这将帮助您找到丢失的拼图块。
-
不相关:
if (expr) { return true; } else { return false; }是return expr;的啰嗦方式
标签: java android android-studio error-handling