-4

According to the second answer here, I can click on some icon within the build window in order to view the errors. The problem is that I cannot find the build window. There is a build variants window but no combination of changes that I can make in it will change anything

Error:(23, 10) error: ')' expected
Error:(27, 28) error: ';' expected
Error:(27, 54) error: ';' expected
Error:(31, 2) error: reached end of file while parsing
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

> Compilation failed; see the compiler error output for details.

This is my program

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    public void myButtonListenerMethod() {
        Button button = (Button)findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RelativeLayout bgElement = (RelativeLayout)findViewById(R.id.activity_main);
                int color = ((ColorDrawable)bgElement.getBackground()).getColor();
                if (color == Color.RED) {
                    bgElement.setBackgroundColor(Color.BLUE);
                } else {
                    bgElement.setBackgroundColor(Color.RED);
                }
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

This is currently what the bottom toolbar in my android studio looks like

enter image description here

Sam
  • 1,765
  • 11
  • 82
  • 176

1 Answers1

1

You just forgot close parenthesis and semicolon ); in button.setOnClickListener() method check it

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RelativeLayout bgElement = (RelativeLayout)findViewById(R.id.activity_main);
                int color = ((ColorDrawable)bgElement.getBackground()).getColor();
                if (color == Color.RED) {
                    bgElement.setBackgroundColor(Color.BLUE);
                } else {
                    bgElement.setBackgroundColor(Color.RED);
                }
            }
        });
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • How can I see the compiler errors though? For when this comes up again. – Sam Mar 15 '18 at 05:37
  • @Jacob check this https://stackoverflow.com/questions/16633956/android-studio-where-is-the-compiler-error-output-window – AskNilesh Mar 15 '18 at 05:48
  • I posted a link to that one in my question. I explained there why it wasn't working for me. – Sam Mar 15 '18 at 05:58