Java运行时异常 [英] Java Runtime Exception

查看:115
本文介绍了Java运行时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的应用程序时,出现以下错误:

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?

如果我尝试: public void notifyChatMessage(String message){... } 错误消失(不是)。

if i try: public void notifyChatMessage(String message){...} the error goes away (NOT).

编辑:经过进一步测试ns上面的内容也会产生错误。

但是如果我尝试: public void notifyChatMessage(Object message){... } 已报告错误。

but if i try: public void notifyChatMessage(Object message){...} the error is reported.

请告知。

编辑: p>

        public void notifyChatMessage(String message){


         AppMessage appMessage = new AppMessage(AppMessage.Target.Chat, message);
         setChanged();
         notifyObservers(appMessage);

     }

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;

}

}

编辑:偶数与错误报告程序继续运行,我看不到任何性能不足即。运行中的错误,这使得使问题的本地化变得更加复杂。

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.

编辑:当我通过netbeans中的调试器运行它时,我得到:调试器在不可编译的源代码上停止。

when i run it through the debugger in netbeans i get: Debugger stopped on uncompilable source code.

编辑:由于跨线程GUI更新而引发异常。正在调查invokeLater和invokeAndWait以寻求解决方案。

解决方案: invokeAndWait

推荐答案

调用 javax.swing.text.FlowView $ FlowStrategy.layoutRow(FlowView.java:546)试图处理 NULL 。看它的签名。 layoutRow(FlowView fv,int rowIndex,int pos)唯一可以 NULL 的是 FlowView fv ,因为 int 基元不能为 NULL 。因此,无需运行代码并逐步调试,我会说某个地方未设置FlowView或将其设置为 NULL

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.

这篇关于Java运行时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆