NullPointerException in Default Token

Questions on using RSyntaxTextArea should go here.

Moderator: robert

NullPointerException in Default Token

Postby Furtwangler » Thu May 03, 2012 4:39 pm


First off, thanks for all of the effort in making all of the RSyntax stuff!

So I'm extending a TextEditorPane and all of its subsequent components. I have a function that changes the color of the syntax highlighting on demand (think preferences window). I also made one to change the font.

I'm calling
Code: Select all
in RSyntaxTextArea for changing the color. I've modified the
Code: Select all
restoreDefaults(Font baseFont, boolean fontStyles)
method in SyntaxScheme with some colors retrieved from a local preference store to do this.

I'm not sure if the above way I'm going about doing this is causing my problem, but (what seems to be randomly), when I call
Code: Select all
Code: Select all
setFont(Font xyz)
in RSyntaxTextArea, I end up with a NullPointerException that traces back to
Code: Select all
if (text[i] == '\t')
(line 198 of the DefaultToken class)

Here is the stack trace if it would help. The line numbers in RSyntaxTextArea may not be normal as I have added a line or two in certain places.

Code: Select all
Exception in thread "Thread-3" java.lang.NullPointerException
   at org.fife.ui.rsyntaxtextarea.DefaultToken.getWidthUpTo(
   at org.fife.ui.rsyntaxtextarea.Token.getWidth(
   at org.fife.ui.rsyntaxtextarea.RSyntaxUtilities.getTokenListWidth(
   at org.fife.ui.rsyntaxtextarea.RSyntaxUtilities.getTokenListWidth(
   at org.fife.ui.rsyntaxtextarea.SyntaxView.getLineWidth(
   at org.fife.ui.rsyntaxtextarea.SyntaxView.calculateLongestLine(
   at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.refreshFontMetrics(
   at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.setSyntaxScheme(
   at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.restoreDefaultSyntaxScheme(

Re: NullPointerException in Default Token

Postby robert » Fri May 04, 2012 2:26 am

There are two likely possibilities I can think of:

Are you doing all UI-related tasks on the Event Dispatch Thread? Assuming so, are you caching Tokens per chance? The same set of Tokens is re-used each call to getTokenListForLine(), so you can't hold onto Tokens between calls, as they'll get invalidated.
User avatar
Posts: 852
Joined: Sat May 10, 2008 5:16 pm

Re: NullPointerException in Default Token

Postby Furtwangler » Fri May 04, 2012 7:33 am

I spent the last 10 hours sitting here pulling in your latest version and slowly adding my modifications back again. The only thing that caused the problem that I can tell (since I think it is gone now), is my main class was a preference listener. It called my update methods for font and colors whenever a preference was changed. The way I save preferences from my GUI is it just sends them all to my preference storage, so it technically fires 14 preference change events. It then called everything else 14 times in a row.

I think either that caused it, or just the fact that it was a preference listener somehow interfered with something? Doesn't make sense but it's one of those two.

I also scrounged around other posts and used your more efficient way of changing colors and fonts on the fly (part of my preferences ability), so I think the way I was doing it before caused problems.

Thank you for the prompt response!

Just FYI, I'm working on a university project called JBrick. It's an IDE meant to be used by blind/visually impaired students for programming lego mindstorm robots.
I've been slowly moving things from SWT/JFace to Swing, hence the need for your project. Thanks again!
Posts: 1
Joined: Thu May 03, 2012 4:40 pm

Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest