2017-01-27 15 views
-1

アンドロイドスタジオを使用してログインアクティビティを構築しようとしています。彼らはエラーが表示され続け、私はそれについて何をすべきか分からない。私は}を使用していて、最後の}には赤い下線が付いています。エラー:解析中にファイルの終わりに達しました

初めて発生しました。

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 
+2

コードを正しくインデントします。これは、不足しているパズルタイルを見つけるのに役立ちます。 – Seelenvirtuose

+2

*無関係:* 'if(expr){trueを返します。 } else {return false; } 'は、' return expr; 'という長時間の方法です。 – Andreas

答えて

0

あなたが適切に

をsetOnClickListenerを閉じていないと、あなたが不足している1 '}'

` @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ブロックの終わりを見てみると、 あなたが);

が欠落しています
関連する問題