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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:16:05+00:00 2026-06-17T17:16:05+00:00

I have tried every possible question here, but couldnt get around it. I have

  • 0

I have tried every possible question here, but couldnt get around it.

I have a java file(android activity) where I declare

private someAdapter someAdapterObj;

Inside onCreate() I call the constructor and get the adapter is instantiated.

this.someAdapterObj= new someAdapter (this,
                       R.layout.item_row,someAdapter.getAllNews());

Inside someAdapter file, I have

private static someArrayList;

I also have a addtoarraylist() inside someAdapter.

Now, I call the addtoarraylist() from onCreate in the mainActivity, but before I instantiate the adapter. This should be possible because, the arraylist is static. But, I get a nullpointer exception when i add to the arraylist. Can someone please help me?

  • 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-17T17:16:06+00:00Added an answer on June 17, 2026 at 5:16 pm

    Any instance or static variable whose type is a class (not a primitive) defaults to null. You need to initialize it – for example:

    private static List<Foo> someArrayList = new ArrayList<Foo>();
    

    However:

    • ArrayList is not thread-safe, so you’ll need synchronization
    • The use of static variables like this is a bit of a code smell (global state); it’s usually cleaner if you can hook your components up appropriately so you don’t need any global state
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked on here and tried every answer available, but it is still
possible noob question but humor me here... I get at least two xml files
I have tried every way I can think of with this, but just not
I have tried making every div 75px and the table within the div but
I am aware that this question has been asked before, but I have tried
This is probably a noob question that I will get slated for but here
Hard to summarize in one question, but here are the details: I have an
Just a quick question. I've tried Googling this but every time you add class
I have tried every install method I can think of to install RPy2 on
I have searched and tried every example regarding singleton, public, and global variables in

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.