Click here to Skip to main content
15,919,178 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to osgi and am currently doing a tutorial on simply a print message which should be displayed on the other project which imports the service. I followed a tutorial, but it's not displaying the message.
this is the code.

activator on service:

C#
public void start(BundleContext context) throws Exception {
        System.out.println("Hello World!! yep");

    }


activator on client project

ServiceReference<HelloService> helloServiceReference;

@SuppressWarnings("unchecked")
public void start(BundleContext context)  {
     System.out.println("Hello World!! bubu");

    helloServiceReference= (ServiceReference<HelloService>) context.getServiceReference(HelloService.class.getName());
    HelloService helloService =(HelloService)context.getService(helloServiceReference);

    System.out.println(helloService.sayHello());
    System.out.println(helloService.sayName());
}



only hello world bubu is being displayed.

this is the output:

osgi> start com.javaworld.sample.HelloWorld
Hello World!! bubu
org.osgi.framework.BundleException: Exception in com.javaworld.sample.helloworld.Activator.start() of bundle com.javaworld.sample.HelloWorld.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:291)
	at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:333)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:209)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:155)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.runConsole(FrameworkConsole.java:140)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:104)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: A null service reference is not allowed.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.getService(BundleContextImpl.java:586)
	at com.javaworld.sample.helloworld.Activator.start(Activator.java:22)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	... 14 more
Nested Exception:
java.lang.NullPointerException: A null service reference is not allowed.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.getService(BundleContextImpl.java:586)
	at com.javaworld.sample.helloworld.Activator.start(Activator.java:22)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:291)
	at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:333)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:209)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:155)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.runConsole(FrameworkConsole.java:140)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:104)
	at java.lang.Thread.run(Unknown Source)
Nested Exception:
java.lang.NullPointerException: A null service reference is not allowed.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.getService(BundleContextImpl.java:586)
	at com.javaworld.sample.helloworld.Activator.start(Activator.java:22)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:299)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:291)
	at org.eclipse.osgi.framework.internal.core.FrameworkCommandProvider._start(FrameworkCommandProvider.java:333)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:209)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:155)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.runConsole(FrameworkConsole.java:140)
	at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:104)
	at java.lang.Thread.run(Unknown Source)



PLease any help?
Posted

Lars Vogella OSGI Turtorial[^] - he has a pretty advanced website that you might like to bookmark.

Your Service is null - that's the problem:

java.lang.NullPointerException: A null service reference is not allowed.
 
Share this answer
 
v2
You may get a quicker answer here[^].
 
Share this answer
 
Comments
Nagy Vilmos 18-Nov-11 10:53am    
Double clear. ;)
Richard MacCutchan 18-Nov-11 12:11pm    
This one took 12. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900