Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Strange Error

  1. #1
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Strange Error

    I write programs with Eclipse and got the next error when running my program,

    the program uses swing frames and dialogs, and the program seems to continue to work after this, but still should i worry?

    The problem is the list nowere points to a line of the program, so i cannot be sure what i did do wrong, or is this an error i don't have to worry about?



    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at javax.swing.BufferStrategyPaintManager.flushAccumulatedRegion(Unknown Source)
    	at javax.swing.BufferStrategyPaintManager.endPaint(Unknown Source)
    	at javax.swing.RepaintManager.endPaint(Unknown Source)
    	at javax.swing.JComponent._paintImmediately(Unknown Source)
    	at javax.swing.JComponent.paintImmediately(Unknown Source)
    	at javax.swing.RepaintManager$3.run(Unknown Source)
    	at javax.swing.RepaintManager$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
    	at javax.swing.RepaintManager.access$1000(Unknown Source)
    	at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
    	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$400(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Strange Error

    Can you create an SSCCE that exhibits this problem? Without looking at your code, we're only guessing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    Quote Originally Posted by KevinWorkman View Post
    Can you create an SSCCE that exhibits this problem? Without looking at your code, we're only guessing.
    Thats just the problem nowhere in the error stack is a reference to any class/method/line in the program.

    therefore i hope you (or somebody else) can give an educated guess what causes it.

    I only use the standard Swing classes, I don't think I do anything particular that caused it

    Was wondering, could it be a JDialog or other swing class that was garbage collected/ closed/ disposed at some time, in some wrong way?

    (there are Jdialogs in the program that are build shown and disposed (and the class that contains the class is class also disposed ) but not at the time the error shows, i am just a bit baffled .

    Am i the only one that gets this kind of error?
    and is it even serious?

    not sure if it even influences the program

    i am just stumped by it, and hope somebody has a hint what could be the cause.

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Strange Error

    Like I said, this is just guessing, but are you updating the GUI from a non-EDT thread? That can cause strange errors like this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    I thought that I didn't need to use SwingUtilities here because it is all in subclasses of JTextComponents and I read somewhere (or did I only imagined it) that JTextComponent was threadSafe because it implemented javax.swing.text.AbstractDocument
    AbstractDocument (Java Platform SE 7 )
    (but to be honest I don't understand it all) and would like to learn all about it


    Java Code:
    package graphical.swing;
    
    
    import java.awt.BorderLayout;
    import java.awt.Font;
    
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollBar;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.WindowConstants;
    
    
    public class TheoremLoggerSwing
    {
      
      private final JPanel      contentPane;
      private final JScrollPane scrollPane;
      private final JTextArea   logArea;
      private final JTextArea   theoremArea;
      private final JScrollBar  vbar;
      
      private JDialog           frame;
    
      // width of textarea  
      private int               width = 70;
        
    
      // constructor
      public TheoremLoggerSwing() {
        this.logArea = new JTextArea();
        this.logArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
        this.logArea.setColumns(this.width);
        this.logArea.setRows(20);
        this.logArea.setEditable(false);
        this.logArea.setWrapStyleWord(true);
        this.logArea.setLineWrap(true);
        
        this.theoremArea = new JTextArea();
        
        this.scrollPane = new JScrollPane(this.logArea);
       
        this.scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        this.vbar = TheoremLoggerSwing.this.scrollPane.getVerticalScrollBar();
        
        this.contentPane = new JPanel();
        this.contentPane.setLayout(new BorderLayout());
        this.contentPane.add(this.theoremArea, BorderLayout.NORTH);
        this.contentPane.add(this.scrollPane, BorderLayout.CENTER);
      }
      
      
      // methods
      
      
      
      public void print(final String log) {
        // add log to logarea
        final int nWidth = 2 + log.length();
        if (this.width < nWidth) {
          this.width = nWidth;
          this.logArea.setColumns(this.width);
        }
        this.logArea.append(log);
        this.adjustBar();
      }
      
      
      private void adjustBar() {
        this.vbar.setValue(this.vbar.getMaximum());
      }
      
      
      public void printNewList(final String nextString) {
        this.logArea.setText(nextString);
        this.adjustBar();
      }
      
      
      protected JPanel getPanel() {
        return this.contentPane;
      }
      
      
      public void setParentloopInfo(final String thInfo) {
        this.theoremArea.setText(thInfo);
      }
      
    }

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: Strange Error

    How is this class used?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    O sorry
    At the beginning of the program I create a JFrame and 2 JPanels (of wich this is one) and they are put into that JFrame and shown, the other JPanel only consist of JButtons and JLabels that are not updated. ( I get the JPanel via getPanel()

    I thought the Error would be caused by some change event and this is the only place where the Gui is changing.

    The program at some times creates other JDialogs and so, but everything is text orientated no drawings, pictures or any of that kind is used.

    btw (not sure if important)

    1) in setParentloopInfo(final String thInfo) the thInfo is a multiline text, sometimes 8 sometimes 6 lines long, and get updated every so often, was wondering could this be the cause of the problem?

    2) the program seems to be working okay , could i just not ignore the error? or could you give some more general help how to prevent it, (i did read about the SwingUtilities Class but to be honnest didn't understand a lot of it.
    Last edited by willemien; 04-09-2013 at 10:54 AM.

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: Strange Error

    And what does your main() method look like?
    Are you just constructing your JFrame?
    Or are you doing it properly and constructing it in an invokeLater() call (ie via SwingUtilities)?
    Swing needs to run on its proper Thread (ie the EDT). If you do any Swing things outside of this thread then it can go wrong.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    Quote Originally Posted by Tolls View Post
    And what does your main() method look like?
    Are you just constructing your JFrame?
    Or are you doing it properly and constructing it in an invokeLater() call (ie via SwingUtilities)?
    Swing needs to run on its proper Thread (ie the EDT). If you do any Swing things outside of this thread then it can go wrong.
    I still need to get used to swing programming
    while in the above JTextArea is threadsafe, the method adjustBar() is not threadsafe if i am correct
    in the above while

    I think the error was on another place, i did n't o every thing in the EDT but now i have two other questions.

    1 > the following bit of code is now NOT on the EDT how can i change it gets there?
    (noticed that even JOptionPane is not threadsafe :(

    Java Code:
      
      
      public boolean getEndProgram() {
        if (this.endProgram) {
          // optionpane to make sure to end program
          final JFrame frame = ParentSwing.getParentJFrame();
          final int endtest = JOptionPane.showConfirmDialog(frame,
              " Stop Engine??", " end engine Question",
              JOptionPane.OK_CANCEL_OPTION);
          if (endtest == JOptionPane.OK_OPTION) {
            return true;
          }
          // continue running
          this.endLabel.setText(" engine Running (again)");
          this.endButton.setText(" press Me to end engine  ");
          this.endProgram = false;
        }
        return false;
      }
    2> another problem in another part of the program

    I have dialog (a JDialog) that can be modal or non Modal (it is made with a facory method and can be interruptinng the thread it is made on , or not interrupting the thread it is made on)
    how can i make it visuable in a threadsafe way???
    (or do i need to make test which kind of JDialog it is and then have two SwingUtilities methods?


    just a bit a rant, need to change so much in my program.

    Why are even simple methods like setting the text on a JLabel, enabling or disabling JButtons, static JOptionPanes and so not thread safe??

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Strange Error

    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    Thanks think i solved it a bit, just will give lots of extra code, why can they not even ,make the most simple things thread safe (but do manage it in some more complex cases)

    also is there somewhere a list of threadsafe Swing methods?

  12. #12
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Strange Error

    Quote Originally Posted by willemien View Post
    Thanks think i solved it a bit, just will give lots of extra code, why can they not even ,make the most simple things thread safe (but do manage it in some more complex cases)

    also is there somewhere a list of threadsafe Swing methods?
    The Swing team decided to leave threading up to the developer. Had they forced thread safety on everybody, Swing would be much less efficient and much harder to maintain.

    There are several functions available to you that make it pretty trivial to guarantee that your Swing application is thread-safe, and it gives you the freedom to use threading to maintain a responsive gui while you do things like loading files and executing long-running algorithms.

    If you really want a list of thread-safe methods, I'd recommend googling something like "list of thread safe methods in swing", but really, I wouldn't rely too much on a list like that. Instead, use good practices and this will never be an issue again.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #13
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: Strange Error

    Quote Originally Posted by willemien View Post
    Thanks think i solved it a bit, just will give lots of extra code, why can they not even ,make the most simple things thread safe (but do manage it in some more complex cases)

    also is there somewhere a list of threadsafe Swing methods?
    There's two basic rules with Swing (which applies to a lot of GUI stuff, eg Android).
    1. Anything affecting the GUI needs to be done on the EDT, that is the thread that controls events on the GUI.
    There are utility methods (invokeLater) that allow you to do this.

    2. Anything that does not directly affect, or may take time to decide what to do with, the gui should be done on its own worker thread. There is a SwingWorker class that allows you to handle this.

    That's all there is to it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    The problem is a bit I use Swing the other way around of what most people do.

    I have a proces (main thread) and that generates logmessages, other information, that are recorded / shown into a swing JComponent, in Swing there are some special functions (like ending the process, show how some result is reached , and others) but the Swingparts are more the receivers of Info than the source of Info / actions )

    I guess the developers of Swing, didn't realise that Swing is sometimes used in this way and that it could do with some special instructions.

    I think I made the Swing parts threadsafe , but then the logging became erratic (even two loggers logging related info, went out of sync)

    it is just complicated to create a threadsafe Logger in Swing, JTextArea.append is threadsafe but to get the knob of a JScrollBar to a position so you can see the latest logging is not threadsafe. (or is there some method to snap the knob to the end of a JscrollBar )

  15. #15
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Strange Error

    Quote Originally Posted by willemien View Post
    The problem is a bit I use Swing the other way around of what most people do.

    I have a proces (main thread) and that generates logmessages, other information, that are recorded / shown into a swing JComponent, in Swing there are some special functions (like ending the process, show how some result is reached , and others) but the Swingparts are more the receivers of Info than the source of Info / actions )

    I guess the developers of Swing, didn't realise that Swing is sometimes used in this way and that it could do with some special instructions.

    I think I made the Swing parts threadsafe , but then the logging became erratic (even two loggers logging related info, went out of sync)

    it is just complicated to create a threadsafe Logger in Swing, JTextArea.append is threadsafe but to get the knob of a JScrollBar to a position so you can see the latest logging is not threadsafe. (or is there some method to snap the knob to the end of a JscrollBar )
    I disagree. I think Swing developers encapsulated your needs perfectly. Actually, that's the entire point of the EDT and Swing's threading policy in the first place- keep long running tasks on another thread, then put gui changes on the EDT. I just think you aren't using it correctly (that's not an insult), and when you get it "right" you'll see the beauty (or at least practicality) of how Swing threading works.

    Look for something like scrollRectToVisible() in whatever component you want to scroll.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. #16
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    Quote Originally Posted by KevinWorkman View Post
    I disagree. I think Swing developers encapsulated your needs perfectly. Actually, that's the entire point of the EDT and Swing's threading policy in the first place- keep long running tasks on another thread, then put gui changes on the EDT. I just think you aren't using it correctly (that's not an insult), and when you get it "right" you'll see the beauty (or at least practicality) of how Swing threading works.

    Look for something like scrollRectToVisible() in whatever component you want to scroll.
    That is not an insult at all, :)

    but there is no scrollRectToVisible() in JTextArea (as far as i know)
    should i use another JTextComponent?

  17. #17
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default Re: Strange Error

    Quote Originally Posted by willemien View Post
    The problem is a bit I use Swing the other way around of what most people do.

    I have a proces (main thread) and that generates logmessages, other information, that are recorded / shown into a swing JComponent, in Swing there are some special functions (like ending the process, show how some result is reached , and others) but the Swingparts are more the receivers of Info than the source of Info / actions )

    I guess the developers of Swing, didn't realise that Swing is sometimes used in this way and that it could do with some special instructions.

    I think I made the Swing parts threadsafe , but then the logging became erratic (even two loggers logging related info, went out of sync)

    it is just complicated to create a threadsafe Logger in Swing, JTextArea.append is threadsafe but to get the knob of a JScrollBar to a position so you can see the latest logging is not threadsafe. (or is there some method to snap the knob to the end of a JscrollBar )
    This is all covered by point 2 in my post above.
    So any updates to your GUI should be done in an invokeLater call.
    That way you don't have to think about which bits are and aren't thread safe.
    Just assume none of the Swing stuff is thread safe, and handle all updates on the EDT.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Strange Error

    Quote Originally Posted by willemien View Post
    but there is no scrollRectToVisible() in JTextArea (as far as i know)
    should i use another JTextComponent?
    The scrollRectToVisible() method is in the JComponent class. JTextArea extends JComponent, so it definitely has the method.

    The api is your best friend: JComponent (Java Platform SE 7 )
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  19. #19
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: Strange Error

    Quote Originally Posted by KevinWorkman View Post
    The scrollRectToVisible() method is in the JComponent class. JTextArea extends JComponent, so it definitely has the method.

    The api is your best friend: JComponent (Java Platform SE 7 )
    help I am just a simple amateur programmer
    Java Code:
        scrollRectToVisible
    
        public void scrollRectToVisible(Rectangle aRect)
    
        Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as JViewport, override this method and perform the scrolling.
    
        Parameters:
            aRect - the visible Rectangle
        See Also:
            JViewport
    And now how do i just make the last line in a JText area visuable?

    how do I get that Rectangle, (does it even exist?)

  20. #20
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: Strange Error

    Quote Originally Posted by willemien View Post
    help I am just a simple amateur programmer
    Java Code:
        scrollRectToVisible
    
        public void scrollRectToVisible(Rectangle aRect)
    
        Forwards the scrollRectToVisible() message to the JComponent's parent. Components that can service the request, such as JViewport, override this method and perform the scrolling.
    
        Parameters:
            aRect - the visible Rectangle
        See Also:
            JViewport
    And now how do i just make the last line in a JText area visuable?

    how do I get that Rectangle, (does it even exist?)
    What have you tried? Where do you want to scroll? Hint: There are methods to get the height of a component. Perhaps try that?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Page 1 of 2 12 LastLast

Similar Threads

  1. strange error in eclipse
    By stevenpalomino in forum New To Java
    Replies: 29
    Last Post: 06-25-2011, 01:46 PM
  2. BufferedReader throwing strange error
    By DragonGhola in forum Advanced Java
    Replies: 4
    Last Post: 06-16-2011, 10:17 AM
  3. Strange unreachable statement error...
    By silafirion in forum New To Java
    Replies: 5
    Last Post: 12-11-2010, 05:05 AM
  4. Strange Error
    By AJArmstron@aol.com in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 09:31 PM
  5. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-25-2008, 11:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •