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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:19:17+00:00 2026-06-05T07:19:17+00:00

Hey guys im trying to make a dynamic scrollable list of selectiondata which a

  • 0

Hey guys im trying to make a dynamic scrollable list of selectiondata which a user can add or remove a spinner and editText when they need to. I have the Spinner and editText being added without an issue, but when i try to delete the one on the bottom of the list.. I get a null pointer error.

At first i thought it was because i was not referencing them properly (relevant editText and spinner data is held in a hashmap) however i have printed out the key names and they appear correct.

Here is the code..

Variables

int count = 0;
HashMap<String,Spinner> spinnerMap = new HashMap<String,Spinner>();
HashMap<String,EditText> editTextMap = new HashMap<String,EditText>();
LinearLayout horzLayout;
LinearLayout layout;

addRow method

 public void addRow()
    {
        Toast.makeText(getApplicationContext(), "editText"+count, Toast.LENGTH_SHORT).show();
        layout = (LinearLayout) findViewById(R.id.scrollerLayout);  
        LinearLayout horzLayout = new LinearLayout(this);
        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        editTextMap.put("editText"+count, new EditText(this));
        editTextMap.get("editText"+count).setWidth(100);
        editTextMap.get("editText"+count).setHeight(40);
        spinnerMap.put("spinner"+count, new Spinner(this));
        List<String> spinnerItems = new ArrayList<String>();
        spinnerItems.add("Super Duper Bad Evil Weed");
        spinnerItems.add("Super Duper Edible Weed");
        spinnerItems.add("Funky Looking Weed");
        spinnerItems.add("Special Weed");

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, spinnerItems);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerMap.get("spinner"+count).setAdapter(dataAdapter);
        horzLayout.setOrientation(LinearLayout.HORIZONTAL);
        layout.addView(horzLayout, p);
        horzLayout.addView(spinnerMap.get("spinner"+count));
        horzLayout.addView(editTextMap.get("editText"+count));
        count++;

    }

RemoveRow Method

    public void removeRow()
{
    count--;
    Toast.makeText(getApplicationContext(), "editText"+count, Toast.LENGTH_SHORT).show();
    horzLayout.removeView(spinnerMap.get("spinner"+count));
    spinnerMap.remove("spinner"+count);
    horzLayout.removeView(editTextMap.get("editText"+count));
    editTextMap.remove("editText"+count);

}

Exact Error Message..

> 06-09 23:48:33.369: E/AndroidRuntime(560): FATAL EXCEPTION: main
06-09 23:48:33.369: E/AndroidRuntime(560): java.lang.NullPointerException
06-09 23:48:33.369: E/AndroidRuntime(560):  at org.unisa.paddockpad.ScreenTwo.removeRow(ScreenTwo.java:83)
06-09 23:48:33.369: E/AndroidRuntime(560):  at org.unisa.paddockpad.ScreenTwo$2.onClick(ScreenTwo.java:52)
06-09 23:48:33.369: E/AndroidRuntime(560):  at android.view.View.performClick(View.java:3511)
06-09 23:48:33.369: E/AndroidRuntime(560):  at android.view.View$PerformClick.run(View.java:14105)
06-09 23:48:33.369: E/AndroidRuntime(560):  at android.os.Handler.handleCallback(Handler.java:605)
06-09 23:48:33.369: E/AndroidRuntime(560):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-09 23:48:33.369: E/AndroidRuntime(560):  at android.os.Looper.loop(Looper.java:137)
06-09 23:48:33.369: E/AndroidRuntime(560):  at android.app.ActivityThread.main(ActivityThread.java:4424)
06-09 23:48:33.369: E/AndroidRuntime(560):  at java.lang.reflect.Method.invokeNative(Native Method)
06-09 23:48:33.369: E/AndroidRuntime(560):  at java.lang.reflect.Method.invoke(Method.java:511)
06-09 23:48:33.369: E/AndroidRuntime(560):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-09 23:48:33.369: E/AndroidRuntime(560):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-09 23:48:33.369: E/AndroidRuntime(560):  at dalvik.system.NativeStart.main(Native Method)

Any help would be greatly appreciated!

update

I am able to delete the views right after they are created inside that method.

  • 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-05T07:19:17+00:00Added an answer on June 5, 2026 at 7:19 am

    horzLayout initialized in addRow ( as local variable ) but not in remove row (where it global)…

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

Sidebar

Related Questions

Hey guys I'm trying to make a GUI which can navigate through JTextAreas when
Hey guys I'm trying to make a basic calculator (polish style) but can't figure
Hey guys, I'm trying to add a textfield.text entry to an array. I want
hey guys, im trying to make a volunteer form, that takes info such as
hey guys, this might be really stupid, but hopefully someone can help. I'm trying
Hey guys I'm trying to add the string 'url( ) ' around my a
Hey guys, I'm trying to make a small addition to a web app I
Hey guys im having a problem. Im trying to make a website with 3
Hey guys i'm trying to convert url which looks like this example.com/sometype/author-name/sort-date or example.com/sometype/author-name/sort-date/something-value/
hey guys i am trying to shuffle the contents of my dynamic array and

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.