Search code examples
eclipse-plugineclipse-rcpe4

Injected messages returning null in eclipse e4


In my plugin, I have created separate packages for maintaining the messages.properties.In that same package I have created my Mesages.java class as well. Following is my message class

   @Message(contributionURI="platform:/plugin/com.chinna.test.properties.messages")
public class Messages {
    public String test1;
    public String test2;
} 

Then injected the message in a different package of the same plugin. like follows. The class in which injected is singleton class.

    @Inject
    @Translation
    Messages messages;

after I injected it I tried access messages.properties in the code like follows

messages.test1

But my application is throwing Null-Pointer exception. since the "messages" is null.

even though I injected, I do not know why "messages" is null.

Could any please help me?


Solution

  • You can only use this in classes which are injected.

    Injection is only done on classes referenced in the Application.e4xmi, some extension points or created/injected using the ContextInjectionFactory make or inject methods.

    For other classes the older style of messages file extending NLS and calling NLS.initializeMessages can be used.