Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are not closing the setOnClickListener properly

and you are missing one '}'

`    @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");
                }
            } // end of onClick method block
        *});* // end of DialogInterface.OnClickListener block
    } // end of onCreate block
}// end of class block`

Look at the end of DialogInterface.OnClickListener block you are missing a );


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...