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?
Any instance or static variable whose type is a class (not a primitive) defaults to
null. You need to initialize it – for example:However:
ArrayListis not thread-safe, so you’ll need synchronization