Java 错误:分析时到达文件末尾

Java 错误:分析时到达文件末尾,java,android,android-studio,error-handling,Java,Android,Android Studio,Error Handling,我正在尝试使用android studio构建登录活动。他们不断出现错误,我不知道该怎么办。我用了},但最后一个}还是有红色的下划线 这是第一次发生 package co5025.example.com.noughtandcrosses; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.support.v7.a

我正在尝试使用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

您没有正确关闭setOnClickListener

你少了一个“}”

`    @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`
查看DialogInterface.OnClickListener块的末尾
您缺少一个

正确缩进代码。这将帮助您找到丢失的拼图块。无关:
if(expr){return true;}否则{return false;}
是说
return expr