ฉันกำลังพยายามส่งกิจกรรมไปยังผู้บริโภค ฉันได้รับ NullPointerException
นี่คือรหัสเหตุการณ์ของฉัน
public class Activator implements BundleActivator {
EventAdmin eventAdmin;
@Override
public void start(BundleContext bundleContext) throws Exception {
System.out.println("started");
Dictionary<String, String> properties = new Hashtable<>();
properties.put("test", "blah");
Event event = new Event("test/sent", properties);
System.out.println("sending");
eventAdmin.sendEvent(event);
}
@Override
public void stop(BundleContext bundleContext) throws Exception {
System.out.println("stopped ");
}
}
นี่คือบันทึก
คุณใช้ฟิลด์ eventAdmin ที่ไม่เคยตั้งค่าไว้ ดังนั้นคุณจะได้รับ NullPointerException ฉันขอแนะนำให้ใช้บริการที่ประกาศแทนและฉีด EventAdmin โดยใช้ @Reference