Java Runtime Exception
when i run my application i get the following error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.FlowView$FlowStrategy.layoutRow(FlowView.java:546)
at javax.swing.text.FlowView$FlowStrategy.layout(FlowView.java:460)
at javax.swing.text.FlowView.layout(FlowView.java:184)
at javax.swing.text.BoxView.setSize(BoxView.java:380)
at javax.swing.text.BoxView.updateChildSizes(BoxView.java:349)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:331)
at javax.swing.text.BoxView.layout(BoxView.java:691)
at javax.swing.text.BoxView.setSize(BoxView.java:380)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1702)
at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1034)
at javax.swing.text.DefaultCaret.repaintNewCaret(DefaultCaret.java:1291)
at javax.swing.text.DefaultCaret$1.run(DefaultCaret.开发者_如何学编程java:1270)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
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)
as the error does not mention any of my classes, how would i go about in finding what is causing this?
if i try: public void notifyChatMessage(String message){...}
the error goes away (NOT).
edit: upon further testing it turns out the above generates the error also.
but if i try: public void notifyChatMessage(Object message){...}
the error is reported.
please advise.
EDIT:
public void notifyChatMessage(String message){
AppMessage appMessage = new AppMessage(AppMessage.Target.Chat, message);
setChanged();
notifyObservers(appMessage);
}
AppMessage:
public class AppMessage implements Serializable {
/**
* Message header for target: game, chat
*/
public enum Target {
Game, Chat
}
/**
* Holds target
*/
public Target target;
/**
* Holds state message
*/
public Object message;
/**
* Construct using parameter data
* @param target
* @param message
*/
public AppMessage(Target target, Object message){
this.target = target;
this.message = message;
}
}
EDIT: even with the error report the program continues to run and i cannot see any lack of performance ie. error in running which is making the task of localizing the problem more complex.
EDIT: when i run it through the debugger in netbeans i get: Debugger stopped on uncompilable source code.
EDIT: the exception is being thrown because of cross thread GUI updates. investigating invokeLater and invokeAndWait for solution.
SOLUTION: invokeAndWait
The call javax.swing.text.FlowView$FlowStrategy.layoutRow(FlowView.java:546)
is trying to process something that is NULL
. Looking at its signature. layoutRow(FlowView fv, int rowIndex, int pos) the only thing that can be NULL
is FlowView fv
since the int
primatives can't be NULL
. So without having the code to run and step debug thru, I would say that somewhere something is either not setting FlowView or setting it to NULL
.
Use the source... start with javax.swing.text.FlowView
line 546
精彩评论