StyledText nullpointer

91 views Asked by At

Im working with SWT StyledText to display data to the user in one part of the window. In another part I have a graph, over which I slide my mouse pointer. As I slide my mouse over a point in the graph, it highlights the corresponding entry in the StyledText Area.

I want my textArea to automatically scroll to the newest change, so I am using .setTopIndex(). To determine the index I need to be able to look at which entries in the textArea changed from not highlighted to highligted, I use the following (to check if my styleRange changed):

styledText.getStyleRangeAtOffset(offset)

So far my program functions correctly. My next check is:

styledText.getStyleRangeAtOffset(offset).isUnstyled 

or

styledText.getStyleRangeAtOffset(offset).foreground 

or something like that. Here enters the problem. When I call any of these I get a nullPointerException.

1

There are 1 answers

0
Valkyrie On

Thank you for all the pointers :) after some debugging I discovered that the unedited styleRange is null. That explains the nullPointer I kept on receiving