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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
Sheriff
Posts: 5555
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.
 
    Bookmark Topic Watch Topic
  • New Topic