Question

I am trying to create a Waveform Control Panel to change the properties of its components. I attempted to apply the example in the Redhawk documentation for a Component Control Panel, but for some reason I get a java.lang.NullPointerException when running the plugin. The error occurs when I attempt to bind the text field to a component property, the exact line where the error occurred is in the comments of the code (at the very bottom).

public class TestControlPanel extends AbstractScaContentEditor<ScaWaveform> {
    private ScaWaveform waveform;
    private ScaComponent myComponent;
    private Text propertyValueField;
    private EMFDataBindingContext context;

    /**
    * {@inheritDoc}
    */
    @Override
    public void createPartControl(final Composite main) {
            main.setLayout(new GridLayout(2, false));
            Group controlGroup = new Group(main, SWT.SHADOW_ETCHED_OUT);
            controlGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
            controlGroup.setText("Controls");
            createControlGroup(controlGroup);
    }

    private void createControlGroup(Composite parent) {
        parent.setLayout(new GridLayout(2, false));

        EObject input = getInput();

        if (input instanceof ScaWaveform) {
            // make local copy of waveform
            waveform = (ScaWaveform) input;
            try {
                waveform.refresh(null, RefreshDepth.FULL);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }       

            label = new Label(parent,SWT.None);
            label.setText("Property Value:");
            propertyValueField = new Text(parent, SWT.BORDER | SWT.FILL);
            myComponent = waveform.getScaComponent("myComponent_1");
            if(myComponent != null)
            {                   
                IObservableValue observable = SCAObservables.observeSimpleProperty(myComponent, "propertyId");
                IObservableValue targetObservable = WidgetProperties.text(SWT.Modify).observeDelayed(5000,propertyValueField);
                if(observable != null && targetObservable != null)
                {
                    // ***** THE BELOW LINE CAUSES A java.lang.NullPointerException ERROR *****
                    context.bindValue(targetObservable, observable);
                    // ***** THE ABOVE LINE CAUSES A java.lang.NullPointerException ERROR *****

                }
            }           
        }

    }

My original guess for the reason for this error was that one of the IObservableValue variables (e.g. targetObservable or observable) was null, which is why I check to make sure the values are not null before binding them. However, this didn't fix the problem and I still got the same error.

Was it helpful?

Solution

From what code I can see it seems as though your field varible "context" was never initialized.

Simply call the no argument constructor: context = new EMFDataBindingContext();

OTHER TIPS

It appears that the context variable is null. I see that you define "context" at the top of the class, but I didn't see where it has been set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top