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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:56:56+00:00 2026-06-12T12:56:56+00:00

I have an arraylist of hashmaps inside the fragment activity class like this. This

  • 0

I have an arraylist of hashmaps inside the fragment activity class like this. This is inside OnCreate method.

   try {
       pp = new Parser(getQuery());
       productData = pp.getData(asynctask, getQuery());
       Log.v("data size:", ""+productData.size()+"");
    } catch (URISyntaxException e) {
    e.printStackTrace();
        } 
    public ArrayList<HashMap<String, String>> getProductData()
      {
      return this.productData;
      }

Here it works fine and data loaded correctly. And the variable productData is declared as public.

Here is my fragment adapter class:

   public class ProductViewPagerAdapter extends FragmentPagerAdapter {
      ProductViewActivity productViewActivity = new ProductViewActivity();;
        public ProductViewPagerAdapter(FragmentManager fm) {
    super(fm);
    }

   @Override
    public Fragment getItem(int i) {
        int temp = productViewActivity.getProductData().size();
        Log.v("size:",""+temp+""); 
        Fragment fragment = new ProductViewFragment();
        Bundle args = new Bundle();
        args.putInt(ProductViewFragment.ARG_SECTION_NUMBER, i + 1);
        fragment.setArguments(args);
        return fragment;
       }

Here the size gives 0. That ends up in Null pointer exception. Where is the issue here?

  • 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-12T12:56:57+00:00Added an answer on June 12, 2026 at 12:56 pm

    That’s your problem:

    ProductViewActivity productViewActivity = new ProductViewActivity();
    You need to pass the instance of the Activity in the constructor of ProductViewPagerAdapter

    public ProductViewPagerAdapter(FragmentManager fm, ProductViewPagerAdapter activity) {
        super(fm);
        mActivity = activity;
        }
    

    OR set it explicitly with a setter function.

    public void setActivity( ProductViewPagerAdapter activity) {
            mActivity = activity;
            }
    

    Then change

    int temp = productViewActivity.getProductData().size();
    

    To:

    int temp = mActivity.getProductData().size();
    

    Hope this helps

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

Sidebar

Related Questions

I have an ArrayList of HashMap like this: ArrayList<HashMap<String, String>> playListSongs = new ArrayList<HashMap<String,
If I have an Application like this: Class Application { List state1 = new
At the moment inside the class I have ArrayList which the objects are stored
I have an ArrayList of Routine objects and I must use this method to
I have set up a HashMap like so: Map<String, ArrayList<String>> theAccused = new HashMap<String,
I have a List of HashMap such as below ArrayList l = new ArrayList
I have arraylist myorderdata . I want to retrieve this arraylist to one String
I have a Arraylist List<?> myList=new ArrayList(); myList = fetchQuery(); //fetches the list of
I have defined an ArrayList in my main class where I am loading data
I have a map: Map<String, String> ht = new HashMap(); and I would like

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.