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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:27:52+00:00 2026-05-24T05:27:52+00:00

I am adding a map to a list and then refreshing the array adapter.

  • 0

I am adding a map to a list and then refreshing the array adapter. This was working perfectly earlier, but now that I am using an addItem() method from two different methods, it throws a NullPointer. I hope my code will clear up what I am saying:

SimpleAdapter adapter;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
ListView listthings;
int[] to;
String[] from;
String painLevelString, timeOfPainString, textTreatmentString,
        painLocation, row1, row2, name;

OnCreate(){
 if(getIntent().getStringExtra("newPainLevel")!= null){
        createNewEditedEntry();

        }
     adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout,
            from, to);
    listthings.setAdapter(adapter);
}

 private void createNewEditedEntry() {
    String newPainLevel = this.getIntent().getStringExtra("newPainLevel");
    String newPainTime =this.getIntent().getStringExtra("newPainTime");
    String newTreatment =this.getIntent().getStringExtra("newTreatment");
    painLevelString = newPainLevel;
    timeOfPainString = newPainTime;
    textTreatmentString = newTreatment;
    row1 = "sample1";
    row2 = "sample2";

    addItem();
    //painItems.remove(getIntent().getStringExtra("position"));
    //adapter.notifyDataSetChanged();

 }

@Override
// on the activityresult,get the string extra, then add the item to the list
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == 1) {
        row1 = data.getStringExtra("com.painLogger.row1");
        row2 = data.getStringExtra("com.painLogger.row2");


        painLevelString = data.getStringExtra("com.painLogger.painLevel");
        painLocation = data.getStringExtra("painLocation");
        timeOfPainString = data.getStringExtra("com.painLogger.painTime");
        textTreatmentString = data
                .getStringExtra("com.painLogger.treatment");
        addItem();
    }
}

// to add the item, put it in the map, and add the map into the list
private void addItem() {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("row_1", row1);
    map.put("row_2", row2);
    map.put("row_3", painLevelString);
    map.put("row_4", painLocation);
    map.put("row_5", timeOfPainString);
    map.put("row_6",textTreatmentString);
    painItems.add(map);
        adapter.notifyDataSetChanged(); //Null Pointer **HERE**
    }

Just to be clear, createNewEditedEntry() and onActivityResult() are never called at the same time and never clash. They are two completely different occurrences. It was working with just the OnActivityResult, but now when I use CreateNewEditedEntry(), it has stopped working. I have also checked and made sure that none of the Strings that I fetch from my intent are null.

  • 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-24T05:27:52+00:00Added an answer on May 24, 2026 at 5:27 am

    You need to initialize adapter before you call createNewEditedEntry in onCreate:

    OnCreate(){
         adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout, from, to);
          if(getIntent().getStringExtra("newPainLevel")!= null){
            createNewEditedEntry();    
          }
    // ...
    }
    

    Otherwise, adapter will be null in addItem called from there (last line of createNewEditedEntry).

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

Sidebar

Related Questions

I am using an array list, a listView, and a custom simple adapter in
Am I right in assuming that adding/removing elements to an std::map does not effect
I have a very large array of doubles that I am using a disk-based
I have a map like this: private Map<String, List<List<String>>> someMap; private List<List<String>> someList1; private
Im having problem's adding map markers to gmaps using jquery. Here is my code
Making a simple map app, plan on adding buttons to mark specific locations But
I'm have a map that looks like this: Map[ A -> Collection[B]] . This
I've been successful at adding map pins to my map overlay but it loads
Adding an element to the head of an alist (Associative list) is simple enough:
Adding Exceptional Handling is a good practise, but I have a doubt, In our

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.