I am trying to build a login activity using android studio. They error keeps appearing and I don't know what to do about it. I have used } and still the last } has a red underlining.
This is the first time it has happened.
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…