Expression Expected error

43,690

You must delete this line Button advanceToQuestionTwo = {Button}; or complete it. You need to put (Button) and not {Button}. Then after that you should call findViewById( id of that button in the xml file).

Share:
43,690
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    In Android Studio I want to a button to start a new Activity. I get an Expression Expected error. Where have I gone wrong?

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
    
      Button advanceToQuestionTwo = {Button};
    
      Button loadNewActivity = (Button) findViewById(R.id.imageButton);
    
      loadNewActivity.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View view) {
          Intent intent = new Intent(MainActivity.this, Stundenplan.class);
          startActivity(intent);
        }
      });
    }