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 8190765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:44:56+00:00 2026-06-07T03:44:56+00:00

I am trying to save the username in shared preferences. I used a web

  • 0

I am trying to save the username in shared preferences. I used a web service to get the username and password from the database and it works perfectly. The problem is with saving the username in shared preferences. I have given the code below. I have commented the place where the problem arises. I get the following exception:

   java.lang.NullPointerException

I cant find whats wrong. please help.

///Login Class////

public class Login extends Activity{

private static final String SOAP_ACTION = "http://tempuri.org/checkLogin";
private static final String OPERATION_NAME = "checkLogin";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://10.0.2.2:54714/WebSite1/Service.asmx";

Button sqllogin;
EditText sqlusername, sqlpassword;
TextView tvData1;
CheckBox cb;

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

    sqlusername = (EditText) findViewById(R.id.etuname1);
    sqlpassword = (EditText) findViewById(R.id.etpass);
    tvData1 = (TextView)findViewById(R.id.textView1); 
    sqllogin = (Button) findViewById(R.id.bLogin);


    sqllogin.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            switch (v.getId()){
            case R.id.bLogin:
            String username = sqlusername.getText().toString();
            String password = sqlpassword.getText().toString();
            SoapObject Request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
            Request.addProperty("uname", String.valueOf(username));
            Request.addProperty("pwd", String.valueOf(password));

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
                    envelope.dotNet = true;
                    envelope.setOutputSoapObject(Request);
                    HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);

                   try  {                    
                    httpTransport.call(SOAP_ACTION, envelope);                       
                    SoapObject result = (SoapObject) envelope.bodyIn;
                    int response =  Integer.parseInt(result.getProperty(0).toString());
                    if(response == 2)//Response is 2 when username and password valid
                        {
                        tvData1.setText("You have logged in successfully"); 
                        savePrefs("CHECKBOX",cb.isChecked()); //This line and the following 3 lines is where the problem is.
                        if (cb.isChecked())
                        {
                            savePrefs("NAME",sqlusername.getText().toString());
                        }
                        Intent openhomepage = new Intent("com.android.disasterAlertApp.HOME");
                        startActivity(openhomepage);
                        }
                    else
                        {
                        tvData1.setText("Invalid Username or password"); 
                        }
                    }  catch (Exception exception)   {
                                  tvData1.setText(exception.toString());                    
                    }
            break;

        }

        }
    });
}

     private void savePrefs(String key, boolean value){
     SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); 
     Editor edit = sp.edit();
     edit.putBoolean(key, value);
     edit.commit();
 }

 private void savePrefs(String key,String value){
     SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); 
     Editor edit = sp.edit();
     edit.putString(key, value);
     edit.commit(); 
 }

}

  • 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-07T03:44:57+00:00Added an answer on June 7, 2026 at 3:44 am

    I dont see where you made cb (the check box ) attached to a view?

    You are getting a null pointer because cb is nothing. You haven’t found its view yet its just a member and that’s it. And since this is also where you are getting your null pointer this is almost certainly what’s going wrong.

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

Sidebar

Related Questions

For a few days, I have been trying to get the username to save
im trying to save a row in my settings table, it works all fine
When trying to save the database using boost serialization, I encounter the segfault that
I'm trying to check username and password by using a For Each Statement. If
I'm trying to save a logged in user's score to my sql database. I
I am trying to find a way how to get the twitter ID from
I'm trying to save some information from a user that is saved on the
I've been trying to figure this problem out all morning. Tried some things from
I'm trying to create a FUNCTION in my Postgres database from a Bash script.
I'm trying to save a file to a Sharepoint server using JAX-WS. The web

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.