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

  • SEARCH
  • Home
  • 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 8027829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:55:57+00:00 2026-06-04T23:55:57+00:00

I used some sample codes and tried to build up a login screen with

  • 0

I used some sample codes and tried to build up a login screen with a username and password for an android app. However, I am getting the following errors "XYZ cannot be resolved or is not a field".

In my program, the XYZ's are the: tv and btn_ok fields in the the loginerror.java file, and btn_sign_in, txt_username, txt_password in the loginactivity.java file.

This is my code for loginerror.java…

    public class LoginError extends Activity {
          Button button;

          public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                System.gc();
                setContentView(R.layout.LoginError);

                TextView textview = (TextView) findViewById(R.id.tv);
                String loginMessage = getIntent().getStringExtra("LoginMessage");
                textview.setText(loginMessage);

                button = (Button) findViewById(R.id.btn_ok);
                button.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View v) {
                            finish();
                      }
                });
          }
    }>

This is my code for loginactivity.java…

    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    import org.apache.http.protocol.HTTP;
    import org.xml.sax.InputSource;
    import org.xml.sax.XMLReader;

    public class LoginActivity extends Activity {
          /** Called when the activity is first created. */
          private static final String TAG = "Login";
          Button signin;
          String loginmessage = null;
          Thread t;
          private SharedPreferences mPreferences; 
          ProgressDialog dialog;

          public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE); 
                if (!checkLoginInfo()) { 
                      signin = (Button) findViewById(R.id.btn_sign_in);
                      signin.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                  showDialog(0);
                                  t=new Thread() {
                                        public void run() {
                                              tryLogin();
                                        }
                                  };
                            t.start(); 
                            }
                      }); 
                }
                else {
                      /*Directly opens the Welcome page, if the username and password is already available 
                      in the SharedPreferences*/
                      Intent intent=new Intent(getApplicationContext(),Welcome.class);
                      startActivity(intent);
                      finish();
                } 
          }

          protected Dialog onCreateDialog(int id) {
                switch (id) {
                      case 0: {
                            dialog = new ProgressDialog(this);
                            dialog.setMessage("Speek is loading");
                            dialog.setIndeterminate(true);
                            dialog.setCancelable(true);
                            return dialog;
                      } 
                }
                return null;
          }
          private Handler handler = new Handler() {

                public void handleMessage(Message msg) {
                      String loginmsg=(String)msg.obj;
                      if(loginmsg.equals("SUCCESS")) {
                            removeDialog(0);
                            Intent intent=new Intent(getApplicationContext(),Welcome.class);
                            startActivity(intent);
                            finish(); 
                      }
                }
          }; 
          public void tryLogin() {
                Log.v(TAG, "Trying to Login");
                EditText etxt_user = (EditText) findViewById(R.id.txt_username);
                EditText etxt_pass = (EditText) findViewById(R.id.txt_password);
                String username = etxt_user.getText().toString();
                String password = etxt_pass.getText().toString(); 
                DefaultHttpClient client = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://www.speek.com");
                List nvps = new ArrayList();
                nvps.add(new BasicNameValuePair("username", username));
                nvps.add(new BasicNameValuePair("password", password));
                try {
                      UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps,
    HTTP.UTF_8);
                      httppost.setEntity(p_entity);
                      HttpResponse response = client.execute(httppost);
                      Log.v(TAG, response.getStatusLine().toString());
                      HttpEntity responseEntity = response.getEntity();
                      Log.v(TAG, "Set response to responseEntity");

                      SAXParserFactory spf = SAXParserFactory.newInstance();
                      SAXParser sp = spf.newSAXParser();
                      XMLReader xr = sp.getXMLReader();
                      LoginHandler myLoginHandler = new LoginHandler();
                      xr.setContentHandler(myLoginHandler);
                      xr.parse(retrieveInputStream(responseEntity));
                      ParsedLoginDataSet parsedLoginDataSet = myLoginHandler.getParsedLoginData(); 
                      if (parsedLoginDataSet.getExtractedString().equals("SUCCESS")) {
                            // Store the username and password in SharedPreferences after the successful login
                            SharedPreferences.Editor editor=mPreferences.edit();
                            editor.putString("UserName", username);
                            editor.putString("PassWord", password);
                            editor.commit();
                            Message myMessage=new Message();
                            myMessage.obj="SUCCESS";
                            handler.sendMessage(myMessage); 
                      } else if(parsedLoginDataSet.getExtractedString().equals("ERROR")) { 
                            Intent intent = new Intent(getApplicationContext(), LoginError.class);
                            intent.putExtra("LoginMessage", parsedLoginDataSet.getMessage());
                            startActivity(intent); 
                            removeDialog(0);
                      } 
                } catch (Exception e) 
                { 
                      Intent intent = new Intent(getApplicationContext(), LoginError.class);
                      intent.putExtra("LoginMessage", "Unable to login");
                      startActivity(intent);
                      removeDialog(0);
                } 
          }
          private InputSource retrieveInputStream(HttpEntity httpEntity) {
                InputSource insrc = null;
                try {
                      insrc = new InputSource(httpEntity.getContent());
                } catch (Exception e) {
                }
                return insrc;
          } 
          //Checking whether the username and password has stored already or not
          private final boolean checkLoginInfo() {
                boolean username_set = mPreferences.contains("UserName");
                boolean password_set = mPreferences.contains("PassWord"); 
                if ( username_set || password_set ) {
                      return true;
                } 
                return false;
          } 
    }

This is my main.xml…

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      xmlns:android="http://schemas.android.com/apk/res/android" >

      <Button
            android:id="@+id/btn_sign_in"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="Sign In"
            android:layout_x="103dp"
            android:layout_y="197dp"/> 
      <EditText
            android:id="@+id/txt_username"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:hint="Username"
            android:singleLine="true"
            android:textSize="18sp"
            android:layout_x="40dp"
            android:layout_y="32dp" />
      <EditText
            android:id="@+id/txt_password"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:hint="Password"
            android:singleLine="true"
            android:textSize="18sp"
            android:password="true"
            android:layout_x="40dp"
            android:layout_y="86dp" />
</AbsoluteLayout>

This is my loginerror.xml file…

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          xmlns:android="http://schemas.android.com/apk/res/android" >
          <TextView 
                android:id="@+id/tv"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:gravity="center_vertical|center_horizontal"/>
          <Button android:id="@+id/btn_ok" android:layout_width="80dp"
                android:layout_height="wrap_content" android:text="OK"
                android:layout_x="83dp" android:layout_y="60dp" />
    </AbsoluteLayout>

The error is occurring at these lines…

1.  TextView textview = (TextView) findViewById(R.id.tv);
2.  button = (Button) findViewById(R.id.btn_ok);
3.  signin = (Button) findViewById(R.id.btn_sign_in);
4.  EditText etxt_user = (EditText) findViewById(R.id.txt_username);
    EditText etxt_pass = (EditText) findViewById(R.id.txt_password);

Do i have to add anything in the main program to fix this problem? What does the problem mean?

  • 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-06-04T23:55:58+00:00Added an answer on June 4, 2026 at 11:55 pm

    You probably have used the wrong R import. If you use android.R than you have found your issue.

    If I understand it correctly, your LoginError.java file is in an external project? If so you will not be able to use any of the generated R class stuff. So no layout files, no drawables, nothing that is located in the res folder.

    If you still want to use an external project, please take a look at the Android Library Project. This might help you as you can use layouts and drawables there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does some PDO::PARAM_??? exist which can be used for dates or timestamps? Sample code:
We tried last night to build some code which would create a new public
I had used several ways to do some simple integer arithmetic in BASH (3.2).
I have a VS project used for my .NET WCF host with some simple
May be some body already used some open source component, writing on jquery. And
I have generally always used some sort of Hungarian Notation for my field names
I've used some neat example's from attached URL's. What I've got so far is
I've written a few Access db's and used some light VBA, and had an
Is there any mechanism in POVRay to export data? I've used some SDL code
Possible Duplicate: Is Java pass by reference? when I used some java class like

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.