我在运行 Java 应用程序时遇到问题,在 Applet Activator 类中,当它打开 gui 时,bundleContext.getServiceReference 会抛出 NPE,在 OSGi 中进行一些搜索后,我发现它发生了,因为没有注册实现 UIService 的服务。我的问题是:这是什么意思?我应该检查什么来修复它?
错误代码:
java.lang.NullPointerException
at net.java.sip.communicator.impl.appletActivator.AppletActivator.openMainGui(AppletActivator.java:57)
at net.java.sip.communicator.impl.appletActivator.AppletActivator.start(AppletActivator.java:40)
at org.apache.felix.framework.util.SecureAction$Actions.run(SecureAction.java:1243)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:620)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1904)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1822)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1192)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:266)
at java.lang.Thread.run(Unknown Source)
来源:
public static <T> T getService(BundleContext bundleContext,
Class<T> serviceClass) {
//This throws the NullPointerException
ServiceReference serviceReference = bundleContext
.getServiceReference(serviceClass.getName());
return (serviceReference == null) ? null : (T) bundleContext
.getService(serviceReference);
}
我是 OSGi 的新手,不了解一些概念。