NullPointException KeyboardNumberInput

Hello,

I’m trying to implement the keyboardNumberInput but i keep geting null pointer exceptions.
I have tryied to rewrite by trying to give it a value and some other stuff but nothing works for me.

Does anyone know what I’m doing wrong?

Here is the Images of my code and where i have used the KeyboardNumberInput.

Thanks in advance.

image
image
image
image

From your screenshots it appreas you have not initialised your keyboard variable. You have told java that there is a variable of type KeyboardNumberInput<Double> called keyboard but that variable is currently empty, it needs to given a value before it can be used, else java will throw a NullPointerException when it tries to perform actions with it (i.e. when you call keyboard.show(). It knows that objects of the type KeyboardNumberInput<Double> have a mathod called show() but it can’t call it because the variable keyboard has not yet been initialised. That is sort of a long explanation, for more information, read up about nullpointerexeptions here

While most native java objects can be defined by the coder, for example:

JLabel myLabel = new JLabel("some text");

In this particular instance, the keyboard in question is of a type defined by the URCap API, and so you need to fetch an instance of a keyboard from there. You can do this by using the ProgramAPIProvider that you can pass to the constructor of your contribution class from the service class. Using the ProgramAPIProvider, perform the following:

keyboard = apiProvider.getUserInterfaceAPI().getUserInteraction().getKeyboardInputFactory().createDoubleKeypadInput();

If you are making keyboards, then I would suggest fetching an instance of the KeyboardInputFactory and just calling the relative create keybaord metod when required.

Hope this helps.
Sam

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.