Caching problem
Hello All,
I have a large resultset of data returned from a database call that is being cached in the app. Now I have to add another cached object and for some reason I'm getting a null pointer.
The cache is declared as a class member as:
private static Map cacheData;
Then an init method is used when the cache class is called (it's using a singleton instance when the first call to the class is made. Init uses:
cacheData = Delegate.retrieveAllData();
which populates the cacheData map object. I don't need that method so I'm just trying to populate the cacheData from a nested method call in that class passing my data in from another map, as in:
private static void initCacheData(Map map){
cacheData.putAll(map);
}
but it's throwing the null pointer when I try to load the cacheData map object. Any idea as to why this is happening and the solution?
Thanks,
James
One simple reason is that the cacheData is null from the very beginning. You should need to initialize your cacheData as in Map cacheData = new Hashtable();
I suspect that the NullPointerException is coming from the line that says cacheData.putAll(map);
This is my assumption that your map has all the data successfully retrieved from the database and you want to put the contents to your cacheData object.
You may also want to post your code to provide detailed problem statement.
No I don't want an instance variable, so I don't want to initialize one. I got it working with this:
cacheData = map;
I create the map and it gets put into the other map without need for a putAll() since there is no instance of cache, it's just a static member of the class. That is why I was throwing a null pointer on cacheData, if it's declared properly you won't even see it in the debugger as a variable, but it's out there as a class member.