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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:20:10+00:00 2026-06-01T23:20:10+00:00

I am creating a GPS based app for Android and there are 2 activities

  • 0

I am creating a GPS based app for Android and there are 2 activities Main and LocNames. Main shows my map and LocNames is to get source and destination that user wants. I want to start LocNames when user selected it from menu, user enters names in boxes and I want result to be send back to Main. But I am getting exceptions in doing so.

Here is how my Main calls LocNames:

    public boolean onOptionsItemSelected(MenuItem item) 
{
    switch (item.getItemId()) 
    {
        case R.id.showMyLocation:
            showCurrentLocation();
            break;
        case R.id.showRoute:
            Intent getLocationsIntent = new Intent(Main.this, LocNames.class);
            startActivityForResult(getLocationsIntent, 1);
            break;
    }

Here is how I am trying to set results in onClick of LocNames:

public void onClick(View v) 
{
    // TODO Auto-generated method stub
    source = sourceText.getText().toString();
    destination = destinationText.getText().toString();     
    Intent result = new Intent(LocNames.this, Main.class);
    result.putExtra("src", source);
    result.putExtra("dest", destination);
    setResult(RESULT_OK, result);
}

But my application crashed when I try to use result returned by LocNames

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
 if(requestCode == 1 && resultCode == RESULT_OK)
    {
        source = data.getStringExtra("src");
        destination = data.getStringExtra("destination");           
    }
}

I have no prior experience in using setResults but documentation says it takes an int and an intent as argument so I am creating intent for that but I get NullPointerException in OnClick of LocNames.

Regards

  • 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-01T23:20:12+00:00Added an answer on June 1, 2026 at 11:20 pm

    You do not need an intent for a specific component. You only need an empty intent. So replace

    Intent result = new Intent(LocNames.this, Main.class);
    

    with

    Intent intent = new Intent();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are creating an enterprise android app that would be installed on several mobiles
I'm creating a gps app for the android! And now I've stumbled upon a
i am creating an augmented reality app that simply visualices a textview when the
I am creating a BREW app that requests the user's position. If the phone
I am creating an application that saves GPS coordinates; I have created a button
Creating a simple app that calculates the speed your going and displays it in
I started doing some thinking about creating an Android application that can be used
I'm creating an app that will do the following: If a mail comes in
I am creating an application which tracks the users location using GPS, stores the
Creating liquid layouts is an immense pain. Now, I totally understand that tables should

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.