0

I am new to Android development, When Android Studio in "MainActivity" class is compiled I get the following error

I have pasted the error log below:

:\Users\kanak\AndroidStudioProjects\SelfDistructText\app\src\main\java\com\example\kanak\selfdistructtext\MainActivity.java:61: error: ';' expected
        public boolean onCreateOptionsMenu(Menu menu){
                                          ^
C:\Users\kanak\AndroidStudioProjects\SelfDistructText\app\src\main\java\com\example\kanak\selfdistructtext\MainActivity.java:61: error: ';' expected
        public boolean onCreateOptionsMenu(Menu menu){
                                                    ^
C:\Users\kanak\AndroidStudioProjects\SelfDistructText\app\src\main\java\com\example\kanak\selfdistructtext\MainActivity.java:69: error: ';' expected
        public boolean onOptionsItemSelected (MenuItem item){
                                            ^
C:\Users\kanak\AndroidStudioProjects\SelfDistructText\app\src\main\java\com\example\kanak\selfdistructtext\MainActivity.java:69: error: ';' expected
        public boolean onOptionsItemSelected (MenuItem item){

I have pasted my MainActivity Class code below:

enter code here

package com.example.kanak.selfdistructtext;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.app.ActionBar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseObject;
import com.parse.ParseUser;


public class MainActivity extends AppCompatActivity{`enter code here`

    public static final String TAG = MainActivity.class.getSimpleName();


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

        // Parase Analytice

        ParseAnalytics.trackAppOpenedInBackground(getIntent());
        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser == null) {
            Intent intent = new Intent(this, LoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
        } else {

            Log.i(TAG, currentUser.getUsername());
        }


        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });


        @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_main, 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);
        }
    }
}
Community
  • 1
  • 1
Haider T
  • 57
  • 2
  • 7
  • 4
    your onCreate is missing the closing curling bracket. – Blackbelt Mar 08 '16 at 08:47
  • Please avoid unnecessary information, as much as possible. Nobody cares about the directory where your code runs (if file I/O is not involved, ofc). So: quote the errors with a '>' syntax and cut them down to the actual error (*e.g.* `69: error: ';' expected public boolean onOptionsItemSelected (MenuItem item){`). Also show, in the pasted code, where line `69` actually is: we cannot know. – Patrizio Bertoni Mar 08 '16 at 08:51
  • 1
    I will do that, thank you so much, this is my first post in stackoverflow – Haider T Mar 09 '16 at 06:02

3 Answers3

1

Replace your code with the following code:

public class MainActivity extends AppCompatActivity{

    public static final String TAG = MainActivity.class.getSimpleName();

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

            // Parase Analytice

            ParseAnalytics.trackAppOpenedInBackground(getIntent());
            ParseUser currentUser = ParseUser.getCurrentUser();
            if (currentUser == null) {
                Intent intent = new Intent(this, LoginActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            } else {

                Log.i(TAG, currentUser.getUsername());
            }


            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);

            FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
            fab.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                            .setAction("Action", null).show();
                }
            });

    }
            @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_main, 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);
            }
        }
}
Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • Thank you so much everybody, I see where the error was. Again thank you for your help. It's a great learning experience for me :) – Haider T Mar 09 '16 at 07:32
  • @HaiderT if this helped you can upvote the answer. Thanks :) – Android Geek Mar 09 '16 at 09:36
  • I have upvoted for you. I had a chance to look at your profile, hopefully I can be like you, you have fantastic experience. It is a pleasure to get to meet you. Again thank you for your help. As I am new to software development. – Haider T Mar 11 '16 at 07:52
  • @HaiderT yeah why not? :) You will be great. – Android Geek Mar 11 '16 at 12:29
0

Functions are not closed properly.

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.app.ActionBar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import com.parse.Parse;
import com.parse.ParseAnalytics;
import com.parse.ParseObject;
import com.parse.ParseUser;


public class MainActivity extends AppCompatActivity{

    public static final String TAG = MainActivity.class.getSimpleName();


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

        // Parase Analytice

        ParseAnalytics.trackAppOpenedInBackground(getIntent());
        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser == null) {
            Intent intent = new Intent(this, LoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
        } else {

            Log.i(TAG, currentUser.getUsername());
        }


        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
}//CLOSE ONCREATE here


        @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_main, 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);
        }

}
Ashlesha Sharma
  • 949
  • 7
  • 15
0

replace

    @Override
    public boolean onCreateOptionsMenu(Menu menu){

with

    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu){

and replace

**public boolean onOptionsItemSelected (MenuItem item){**

with

public boolean onOptionsItemSelected (MenuItem item){

Community
  • 1
  • 1