我在運行Java應用程序時遇到問題,在Applet Activator類中打開 gui bundleContext.getServiceReference在OSGi中進行一些搜索後拋出一個NPE它在我看來是因爲存在沒有服務註冊,實現了UIService .. 我的問題是:這是什麼意思?我應該檢查什麼來解決它?osgi中的bundleContext.getServiceReference
錯誤代碼:
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,不明白的一些概念。
在getService()函數中,當你說「失敗」時有點奇怪,而你的堆棧跟蹤指向AppletActivator.openMainGui函數。是否有可能您只複製了異常堆棧追蹤的頂部,而不是更重要的「引發者」部分? –
對不起,我的意思是函數調用拋出NullPointerException,並且OpenMainGui調用getService .. –
這就是記錄器的最後一個輸出,之後應用程序停止 –