Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

java - error: reached end of file while parsing

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

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

1 Reply

0 votes
by (71.8m points)

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 );


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...