Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

NPE while caching using coherence in java

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ranchers,

I am trying to build a simple caching application using coherence. I am able to bring up the service by running cache-server.cmd from the directory where coherence was installed (C:\Oracle\Middleware\Oracle_Home\coherence\bin) and push or pop value from the cache via command line (cmd). But when I try to do the same using Java code, I am getting the following error:
Value of the NamedCache variable cache after calling getCache(): null
Exception in thread "main" java.lang.NullPointerException
at com.learn.coherence.main.TestCacheMainOne.main(TestCacheMainOne.java:9)

The code is fairly simple and small. I am marking the line causing this exception in bold.
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
public class TestCacheMainOne {
public static void main(String[] args) {
NamedCache cache = CacheFactory.getCache("VirtualCache");
System.out.println("Value of the NamedCache variable cache after calling getCache(): " + cache);
String key = "key1";
String value = "value1";
cache.put(key, value);
String receivedValue = (String) cache.get(key);
System.out.println(receivedValue);
}
}

Please help me in getting over this obstacle.
 
Marshal
Posts: 5466
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
This is near enough the exact same problem you started to tell us about over in this other thread of yours. Why don't you continue the discussion over there rather than creating near duplicate threads.
 
It runs on an internal combustion engine. This ad does not:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic