Several errors when compiling in Android Studio

Asked

Viewed 486 times

0

I created a project in Android Studio (yes, the Rootear device). I finished the main screen and created the action for the Root button. Pórem, after I created a screen of "Welcome" came up several errors. One of them are these;

Error:(23, 10) error: ')' expected
Error:(27, 39) error: ';' expected
Error:(27, 49) error: ';' expected
Error:(34, 41) error: ';' expected
Error:(34, 55) error: ';' expected
Error:(47, 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 one is the welcome screen mainactivity:

package com.hyanhythalo.rootfox;

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

public class Main2Activity extends AppCompatActivity {

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

        final Button button = (Button) findViewById(R.id.welcome_ok_button);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

1 answer

2

Failed to include the closing of the parentheses and the semicolon when declaring the event OnClickListener. Below is the correction:

button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            finish();
        }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.