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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:07:41+00:00 2026-05-29T11:07:41+00:00

I have two activities; Home is my first activity and Settings is my second

  • 0

I have two activities; Home is my first activity and Settings is my second activity.

The Settings activity is called from the menu of the Home activity, and returns data to home activity through intent.

But first time when I run the android application, the intent will be empty because the second activity is not yet called, so I get exception there (Java null pointer exception).

Can anybody help me out to handle this solution?

EDIT: Code

First Activity:

public class LoginActivity extends Activity {

    public static final int SETTINGS_ID = 1;
    Intent intn;

    EditText edt1;
    EditText edt2;
    String user, pass;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        intn= new Intent(this,SettingsActivity.class);
    }

    private class HttpConnectionRequest extends AsyncTask<Void, Void, Void>{
        @Override
        protected Void doInBackground(Void...params) {
            // TODO Auto-generated method stub
            //Code not included
        }
        return null;
    }
}

public void login(View V){

    edt1 = (EditText) this.findViewById(R.id.editText1);
    edt2 = (EditText) this.findViewById(R.id.editText2);
    user = edt1.getText().toString();
    pass = edt2.getText().toString();
    System.out.println("Username-->" + user);
    System.out.println("Password-->" + pass);
    String url="";
    url = getIntent().getExtras().getString("serverurl");
    System.out.println("url----->"+url);

    if(((null==user) || ("".equals(user))) && ((null==pass) || ("".equals(pass)) )){
        Toast.makeText(getApplicationContext(), "Please provide username and password", Toast.LENGTH_SHORT).show();  
    }
    else if((null==user) || ("".equals(user))){
        Toast.makeText(getApplicationContext(), "Please provide username", Toast.LENGTH_SHORT).show();  
    }
    else if ((null==pass) || ("".equals(pass))){
        Toast.makeText(getApplicationContext(), "Please provide password", Toast.LENGTH_SHORT).show();  
    }

    if ((null==url) || ("".equals(url))) {
        Toast.makeText(getApplicationContext(), "Please provide the Server url Settings->Server URL->Save", Toast.LENGTH_SHORT).show();  
    }

    HttpConnectionRequest conn= new HttpConnectionRequest();
    conn.execute();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // boolean result = super.onCreateOptionsMenu(menu);
    menu.add(0, SETTINGS_ID, 0, "Settings");
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.layout.menu, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case SETTINGS_ID:
            //this.finish();
            this.startActivity(intn);
            System.out.println("This Invoked . . .");
            break;
        }
        return false;
    }
}

Second activity

public class SettingsActivity extends Activity {

    EditText edt1;
    Intent intn;

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        intn = new Intent (this,LoginActivity.class);
    }

    public void save(View v){
        edt1= (EditText) this.findViewById(R.id.serverurl);
        String url = edt1.getText().toString();
        intn.putExtra("serverurl",url);
        startActivity(intn);        
    }
}
  • 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-29T11:07:41+00:00Added an answer on May 29, 2026 at 11:07 am

    You can do a check for the resultCode as below.

    http://developer.android.com/guide/topics/fundamentals/activities.html#StartingAnActivityForResult

    Also, can you identify where exactly you get the exception? (post some code maybe)

    EDIT:

    Ok, I still donT know where you are calling your login() method but you can do this check to avoid null exceptions in the line you mentioned:

    if( getIntent().getExtras() != null)
    {
      //do here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two activities. The first one executes the second one. Intent i =
I have two activities The first one gets some data from a content provider,
I have two activities. The first activity display list of the users with short
I have two activities or screens. The second activity has an AlertDialogBox with radiobuttons
I have two different activities. The first launches the second one. In the second
I have two activities. Home activity contain a list view with two buttons named
I have two activities A and B, and from activity A, I click on
I have two activities, one is main and I have another activity called Test
I have two activities and the first is generating properly however the second is
I have two activities, Activity A and Activity B. I pass objects from Activity

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.