Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3631334
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:23:02+00:00 2026-05-19T00:23:02+00:00

I created this Sign-In page. I start by declaring variables for username/password & buttons.

  • 0

I created this Sign-In page. I start by declaring variables for username/password & buttons. If user enters “test” as username & “test” as password and hits the login button, its supposed to go to the DrinksTwitter.class activity, else throw error message I created. To me the code and login makes perfect sense. I’m not sure why it wont go to the next activity I want it to go to

package com.android.drinksonme;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class Screen2 extends Activity {

    // Declare our Views, so we can access them later
    private EditText etUsername;
    private EditText etPassword;
    private Button btnLogin;
    private Button btnSignUp;
    private TextView lblResult;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Get the EditText and Button References
                etUsername = (EditText)findViewById(R.id.username);
                etPassword = (EditText)findViewById(R.id.password);
                btnLogin = (Button)findViewById(R.id.login_button);
                btnSignUp = (Button)findViewById(R.id.signup_button);
                lblResult = (TextView)findViewById(R.id.result);

                    // Check Login
                       String username = etUsername.getText().toString();
                       String password = etPassword.getText().toString();

         if(username.equals("test") && password.equals("test")){

            final Intent i = new Intent(Screen2.this, DrinksTwitter.class);
            btnLogin.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {     
                startActivity(i);              
                }

                  // lblResult.setText("Login successful.");        

                        else { /* ERROR- Syntax error on token "else", { expected */
                                    lblResult.setText("Invalid username or password.");
                                }
                            }
                        });

                        final Intent k = new Intent(Screen2.this, SignUp.class);
                        btnSignUp.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) { 
                                startActivity(k);
                            }
                        }); /* ERROR- Syntax error, insert "}" to complete Statement*/
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:23:03+00:00Added an answer on May 19, 2026 at 12:23 am

    I only briefly looked at your code, but I don’t understand what you’re doing (in that order).

    You’re checking the password & username on the OnCreate method, which, barring any autofilling, the textboxes will be blank.

    Then you declare your onClickListeners.

    Try restructuring it to be something like this (pseudo-code):

    OnCreate
        user = usertextbox
        pass = passtextbox
        login.setOnClick
            if user == validUsername && pass == validPass
                Intent i = new Intent(blah.this, blah.class)
                startActivity(i)
            else
                Intent i = new Intent(blah.this, login.class)
                startActivity(i)
    

    This is how I have my app’s login screen.

    In short, you have to make the check occur in the OnClickListener of the action button, not in the OnCreate method of the activity. The way it is now, the form is created, and the textboxes are blank. Then immediately afterwards, they’re compared against some values. That call will always fail to execute, so all of the code in your If statement scope will be ignored indefinitely.

    Also, the reason Eclipse is giving you that error is because you’re trying to place an else statement inside of a class definition.

    When you declare a new OnClickListener() { }, you’re essentially declaring a class. So you’re in the class scope, not the if scope.

    That would be like trying to do:

    class test {
        else {
            doStuff();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login script that does this: $_SESSION['username']=$username; $_SESSION['password']=$password; If the user logged
I created this regex to match all words that start with @ in my
I created this form: <form method=post action=process-form.php id=emailForm name=emailForm target=_self> <h4>Sign up to be
I have created this login page. <asp:Label id=Label2 style=Z-INDEX: 103; LEFT: 112px; POSITION: absolute;
My test page is currently displaying : Test Page which is a good sign
Possible Duplicate: Why PHP variables start with a $ sign symbol? I have looked
I created this program: #include <iostream> #include <fstream> using namespace std; int main ()
I created this layout of successive text input fields, 1- Enter data into empty
I created this regular expression to validate names: ^[a-zA-Z0-9\s\-\,]+.\*?$ Is there a way add
I created this example The remove function doesn't work, and I can't figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.