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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:13:24+00:00 2026-06-16T04:13:24+00:00

I have a trouble with my app. I have an activity which name is

  • 0

I have a trouble with my app.
I have an activity which name is PetActivity. In this activity are some values… and a button(update) too. This button will switch the user to another activity called UpdateActivity in which he can edit the values from PetActivity. There is a save button which should finish this activity and re-open the PetActivity. I’ve got error in this action… (null pointer exception)

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project/com.example.project.PetActivity}: java.lang.NullPointerException

PetActivity onclick code:

if (v.getId() == R.id.button1updateAP) {
        Intent i = new Intent(PetActivity.this, UpdateActivity.class);
        Bundle ext = getIntent().getExtras();
        String idOfPet = ext.getString(IDR);        
        i.putExtra(UpdateActivity.ID, idOfPet);         
        startActivity(i);
        finish();           
    }

UpdateActivity onclick code:

if (v.getId() == R.id.button1saveAU) {
        MyDatabaseHelper db = new MyDatabaseHelper(this);

        Pet petU = new Pet();
        petU.setID(id);
        petU.setName(TVname.getText().toString());          
        petU.setAge((ETage.getText().toString()));
        petU.setWeight(ETweight.getText().toString());          
        db.updatePet(petU);
        db.close();

        DatabaseWeight dbw = new DatabaseWeight(this);          
        dbw.addPetWeight(new Pet(petU.getID(), petU.getWeight()));          

        Intent i2 = new Intent(this, PetActivity.class);
        startActivity(i2);
        finish();
    }

When i tried this, it was ok:

Intent i2 = new Intent(this, ListActiv.class);
startActivity(i2);
finish();

this code had switch me to List and the i could go to refreshed PetActivity,but I have to get straight to the PetActivity.

I would be very thankful for any suggestions.

Thanks!

  • 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-16T04:13:25+00:00Added an answer on June 16, 2026 at 4:13 am

    You don’t need to call finish() after launching UpdateActivity from PetActivity, and inside UpdateActivity when your work is done just call setResult() before finish()…

    Your code should be for onClick of MainActivity

    if (v.getId() == R.id.button1updateAP) {
            Intent i = new Intent(PetActivity.this, UpdateActivity.class);
            Bundle ext = getIntent().getExtras();
            String idOfPet = ext.getString(IDR);        
            i.putExtra(UpdateActivity.ID, idOfPet);         
            startActivityForResult(i,some request code ););
            finish();           
        }
    

    For onClick of ChildActivity

    if (v.getId() == R.id.button1saveAU) {
            MyDatabaseHelper db = new MyDatabaseHelper(this);
    
            Pet petU = new Pet();
            petU.setID(id);
            petU.setName(TVname.getText().toString());          
            petU.setAge((ETage.getText().toString()));
            petU.setWeight(ETweight.getText().toString());          
            db.updatePet(petU);
            db.close();
    
            DatabaseWeight dbw = new DatabaseWeight(this);          
            dbw.addPetWeight(new Pet(petU.getID(), petU.getWeight()));          
            if(/*task completed successfully*/){
               setResult(RESULT_OK);
            }else{
               setResult(RESULT_CANCELED); 
            }
            finish();
        }
    

    Now in your Parent Activity you can check these values inside onActivityResult()

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            Log.i(LOG_TAG, "Inside onActiviy Result : "+resultCode);
            if ( resultCode == RESULT_OK ) {
                Toast.makeText(this, "Update executed successfully..", Toast.LENGTH_SHORT).show();
            }else if ( resultCode == RESULT_CANCELED ) {
                Toast.makeText(this, "There was an error", Toast.LENGTH_SHORT).show();
            }
        }
    

    Also see various intent flags in doc..

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

Sidebar

Related Questions

Having some trouble passing values from one class to another. I basically have a
I have some trouble in my app where sometimes it works and displays all
I have some trouble while try using broadcast receiver. Target: I have three app
I have trouble with my app, when i'm trying to get active user from
i am developing an android app using phonegap. I have trouble displaying special characters
I have a basic expressjs app (using jade), but I am having trouble rendering
I have a rails app that has asynchronous processing, and I'm having trouble getting
I have trouble figuring out why a simple division like this one always returns
I have trouble doing this... You may want to get the same result as
I'm writing an Android app. I have a main method, which creates and runs

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.