Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Adding Users Using Parse.com Logging In

Logging in Error

I cut and pasted just like the video stated, I'm on Android Studio, but I received a BUNCH of errors. I worked through most of them, but keep getting these errors in my loginactivity2 file:

package lejacque1.ribbit2;

import android.app.AlertDialog; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;

import com.parse.LogInCallback; import com.parse.ParseException; import com.parse.ParseUser; import com.parse.SignUpCallback;

public class LoginActivity2Activity extends ActionBarActivity {

protected EditText mUsername;
protected EditText mPassword;
protected Button mLoginButton;

protected TextView mSignUpTextView;

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

    mSignUpTextView = (TextView) findViewById(R.id.signUpText);
    mSignUpTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(LoginActivity2Activity.this,
                    SignUpActivity2Activity.class);
            startActivity(intent);

        }
    });

    mUsername = (EditText) findViewById(R.id.usernameField);
    mPassword = (EditText) findViewById(R.id.passwordField);
    mLoginButton = (Button) findViewById(R.id.loginButton);
    mLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String username = mUsername.getText().toString();
            String password = mPassword.getText().toString();

            username = username.trim();
            password = password.trim();

            if (username.isEmpty() || password.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity2Activity.this);
                builder.setMessage(R.string.login_error_message)
                        .setTitle(R.string.login_error_title)
                        .setPositiveButton(android.R.string.ok, null);

                AlertDialog dialog = builder.create();
                dialog.show();
            } else {
                ParseUser.logInInBackground(username, password, new LogInCallback() {
                    @Override
                    public void done(ParseUser user, ParseException e) {
                        if (e == null) {
                            Intent intent = new Intent(LoginActivity2Activity.this, MainActivity.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity2Activity.this);
                            builder.setMessage(e.getMessage())
                                    .setTitle(R.string.login_error_title)
                                    .setPositiveButton(android.R.string.ok, null);

                            AlertDialog dialog = builder.create();
                            dialog.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_login_activity2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected; (MenuItem MenuItem item);
    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);

The errors are: @Override not applicable to local variable, ')' expected, ';' expected, Modifier public not allowed here, Unexpected token, Variable 'item' is never assigned, Cannot return a value from a method with void result type, and Variable' onOptionsItemSelected' is never used

The part of the code with the error is:

@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_login_activity2, menu); return true; }

    @Override
    public boolean onOptionsItemSelected; (MenuItem MenuItem item);
    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);

Thanks for any help.

I tried it but its still showing the same errors.

I stand corrected, I went through it again and caught a few. It fixed the poronle. Thanks.

Sanjiv Saha
Sanjiv Saha
1,110 Points

It gives a ClassCastException..instead of extending FragmentActivity in MainActivity extend ActionBarActivity and make this change in the MainActivity..just paste this code in the in the MainActivity where a very similar code exists:

for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { // Create a tab with text corresponding to the page title defined by // the adapter. Also specify this Activity object, which implements // the TabListener interface, as the callback (listener) for when // this tab is selected. actionBar.addTab( actionBar.newTab() .setText(mSectionsPagerAdapter.getPageTitle(i)) //Edited to change from ActionBarActivity to FragmentActivity .setTabListener(this)); }