Setting Text in RSyntaxTextArea

Questions on using RText should go here.

Moderator: robert

Setting Text in RSyntaxTextArea

Postby Hanan Awwad » Wed Sep 12, 2012 8:26 am

Hi,


I have tried to set some text in RSyntaxTextArea but it throws nullPointerException; while when i tried to set empty string it works

Can you tell me why this happening?
Hanan Awwad
 

Re: Setting Text in RSyntaxTextArea

Postby robert » Wed Sep 12, 2012 1:23 pm

If you're using the RSyntaxTextArea(String) constructor, it could be this bug (I thought it had been fixed, but I guess not). If that's the case, just try calling setText(String) or read(Reader) after creating with one of the other constructors.

If that's not the case, you'll have to post an example that shows the behavior you're seeing for me to investigate further.
User avatar
robert
 
Posts: 798
Joined: Sat May 10, 2008 5:16 pm

Re: Setting Text in RSyntaxTextArea

Postby nguyen » Fri Oct 26, 2012 1:19 pm

Hello,

I have the same problem as posted. I tried to use the XML format, then I set text separately as you mention, but the problem sometimes occurs.
I develop & run the program in Linux, and it happens about 70% for the same input. But when I move the program to Windows to run, it does not happen. I'm using Ubuntu 11.04. Here is part of my code:
Code: Select all
    private javax.swing.JScrollPane xmlScrollPane;
    private RSyntaxTextArea xmlEditor;

    xmlScrollPane = new javax.swing.JScrollPane();
    xmlEditor = new RSyntaxTextArea();
    xmlEditor.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
    xmlEditor.setTabSize(4);
    xmlScrollPane.setViewportView(xmlEditor);

    xmlEditor.setText(longXmlText);


And here is the exception thrown
Code: Select all
java.lang.NullPointerException
   at org.fife.ui.rsyntaxtextarea.TokenMakerBase.addToken(TokenMakerBase.java:127)
   at org.fife.ui.rsyntaxtextarea.TokenMakerBase.addToken(TokenMakerBase.java:103)
   at org.fife.ui.rsyntaxtextarea.modes.XMLTokenMaker.addToken(XMLTokenMaker.java:347)
   at org.fife.ui.rsyntaxtextarea.modes.XMLTokenMaker.addToken(XMLTokenMaker.java:332)
   at org.fife.ui.rsyntaxtextarea.modes.XMLTokenMaker.addToken(XMLTokenMaker.java:321)
   at org.fife.ui.rsyntaxtextarea.modes.XMLTokenMaker.yylex(XMLTokenMaker.java:832)
   at org.fife.ui.rsyntaxtextarea.modes.XMLTokenMaker.getTokenList(XMLTokenMaker.java:446)
   at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.getTokenListForLine(RSyntaxDocument.java:376)
   at org.fife.ui.rsyntaxtextarea.SyntaxView.getLineWidth(SyntaxView.java:209)
   at org.fife.ui.rsyntaxtextarea.SyntaxView.calculateLongestLine(SyntaxView.java:119)
   at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.refreshFontMetrics(RSyntaxTextArea.java:1467)
   at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.addNotify(RSyntaxTextArea.java:401)
   at java.awt.Container.addNotify(Container.java:2578)
   at javax.swing.JComponent.addNotify(JComponent.java:4685)
   at java.awt.Container.addNotify(Container.java:2578)
   at javax.swing.JComponent.addNotify(JComponent.java:4685)
   at java.awt.Container.addNotify(Container.java:2578)
   at javax.swing.JComponent.addNotify(JComponent.java:4685)
   at java.awt.Container.addImpl(Container.java:1068)
   at java.awt.Container.add(Container.java:927)
   at org.netbeans.modules.options.OptionsPanel.setCurrentCategory(OptionsPanel.java:185)
   at org.netbeans.modules.options.OptionsPanel.access$100(OptionsPanel.java:98)
   at org.netbeans.modules.options.OptionsPanel$CategoryButton.mouseReleased(OptionsPanel.java:528)
   at java.awt.Component.processMouseEvent(Component.java:6288)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
   at java.awt.Component.processEvent(Component.java:6053)
   at java.awt.Container.processEvent(Container.java:2041)
   at java.awt.Component.dispatchEventImpl(Component.java:4651)
   at java.awt.Container.dispatchEventImpl(Container.java:2099)
   at java.awt.Component.dispatchEvent(Component.java:4481)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
   at java.awt.Container.dispatchEventImpl(Container.java:2085)
   at java.awt.Window.dispatchEventImpl(Window.java:2478)
   at java.awt.Component.dispatchEvent(Component.java:4481)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:643)
   at java.awt.EventQueue.access$000(EventQueue.java:84)
   at java.awt.EventQueue$1.run(EventQueue.java:602)
   at java.awt.EventQueue$1.run(EventQueue.java:600)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
   at java.awt.EventQueue$2.run(EventQueue.java:616)
   at java.awt.EventQueue$2.run(EventQueue.java:614)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:613)
   at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:137)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


When I put the try catch block arround the setText method, I can catch the Throwable clause.

Do you have any idea about it???
nguyen
 

Re: Setting Text in RSyntaxTextArea

Postby robert » Fri Oct 26, 2012 1:35 pm

I don't see how your exception can be anything but a threading issue. Here's the relevant code from TokenMakerBase.java:

java code:

124	currentToken.setNextToken(tokenFactory.createToken(array,
125 start,end, startOffset, tokenType));
126 previousToken = currentToken;
127 currentToken = currentToken.getNextToken();


At line 127, the only possible NPE is from currentToken being null, but it wasn't null at line 124. So my only idea is that you're doing some UI handling (likely with the RSyntaxTextArea instance) off the EDT. Is that possible?
User avatar
robert
 
Posts: 798
Joined: Sat May 10, 2008 5:16 pm

Re: Setting Text in RSyntaxTextArea

Postby nguyen » Fri Nov 09, 2012 4:05 pm

Hi robert,

As you guess, the problem does not come from the RSyntaxTextArea, instead it comes from the Netbeans platform when it calls a CallableAction, then it might cause NPE. After calling directly the method without using the CallableAction, my program works perfectly.

BTW, thank you for your discussion.
nguyen
 


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron