在一个代号为iOS的应用程序上研究Java.Lang.NullPointerException [英] Investigate Java.Lang.NullPointerException on a Codename One iOS app

查看:47
本文介绍了在一个代号为iOS的应用程序上研究Java.Lang.NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我尝试调查此问题: https://github.com/codenameone/CodenameOne / issues / 2975
我在这里写的是问我如何才能准确地找到问题所在。此错误令人沮丧。

Today I tried to investigate this issue: https://github.com/codenameone/CodenameOne/issues/2975 I'm writing here to ask how I can find exactly what goes wrong. This bug is frustrating.

基本上,仅在iOS上,出现此错误,发生在某些随机应用程序使用后:

Basically, on iOS only, I have this error, that happens after some random app usage:

java.lang.NullPointerException
    at com_codename1_ui_Form.pointerReleased:3758
    at net_informaticalibera_cn1_simpleapi_OuterForm.pointerReleased:360
    at com_codename1_ui_Component.pointerReleased:4679
    at com_codename1_ui_Display.handleEvent:2289
    at com_codename1_ui_Display.edtLoopImpl:1214
    at com_codename1_ui_Display.mainEDTLoop:1132
    at com_codename1_ui_RunnableWrapper.run:120
    at com_codename1_impl_CodenameOneThread.run:176
    at java_lang_Thread.runImpl:153

我已覆盖 pointerReleased 方法,以查看抛出前一个异常时 x y 是否可接受的值,似乎是这样:

I've overridden the pointerReleased method to see if x and y are acceptable values when the previous exception is thrown, it seems so:

@Override
    public void pointerReleased(int x, int y) {
        try {
            super.pointerReleased(x, y);
        } catch (Exception ex) {
            Log.p("OuterForm.pointerReleased ERROR, x->" + x + ", y->" + y + ", https://github.com/codenameone/CodenameOne/issues/2975");
            Log.e(ex);
            SendLog.sendLogAsync();
        }
    }

使用该替代,等同于碰撞保护功能,第一次发生此异常后, TextArea 组件将不再可用:点击它们不会打开VKB。

Using that override, that is equivalent to the crash protection feature, after the first time that this exception happens the TextArea components are not more usable: the tap on them doesn't open the VKB.

简而言之,iOS端口 Form.pointerReleased 内有一个 NullPointerException :如何我可以发现该方法的哪一行引发异常?我希望找到有助于解决错误的信息。

In short, there is a NullPointerException inside the iOS port of Form.pointerReleased: how can I discover which line of that method throws the exception? I hope to find info that can help for the bug resolution.

推荐答案

问题是方法<$ c的代码$ c>类 codename1 / ui / Form.java rel = nofollow noreferrer> Form 都在 try中...最终,隐藏了异常的实际原因。
为了得到实际的原因,我在应用程序的 BaseForm 类中使用了以下覆盖,它扩展了 Form 并且我将其用作所有其他其他形式的超类:

The problem is that the code of the method public void pointerReleased(int x, int y) of the class Form is all inside a try... finally, that hides the actual cause of the exception. To get the actual cause, I used the following override in the BaseForm class of my app, that extends Form and that I use as superclass for all other Forms:

@Override
    public void pointerReleased(int x, int y) {
        try {
            Component cmp = instance.getResponderAt(x, y);
            if (cmp != null) {
                cmp.pointerReleased(x, y);
            }
        } catch (Exception ex) {
            Log.p("BaseForm.pointerReleased ERROR, x->" + x + ", y->" + y + ", https://github.com/codenameone/CodenameOne/issues/2975");
            Log.e(ex);
            SendLog.sendLogAsync();
        }
    }

正如预期的那样,这给了我实际的原因错误,该错误位于 TextArea actionListener的lambda表达式内:更具体而言,问题是在 revalidate 上, code>容器引用在某些情况下可能为 null (奇怪的是,这仅在iOS上发生)。之后,我删除了先前的替代(破坏了某些功能),修复了代码,防止在 null revalidate >对象(条件为 if )并且错误消失了(我使用该应用程序的长时间使用进行了测试)。

As expected, this gave me the actual cause of the bug, that was inside a lambda expression of a TextArea actionListener: more specifically, the issue was a revalidate on an Container reference that can be null in some circumstances (oddly, this happens only on iOS). After that, I removed the previous override (that broke some functionalities), I fixed my code preventing the revalidate on a null object (with an if condition) and the bug disappeared (I've done a test with a long usage of the app).

这篇关于在一个代号为iOS的应用程序上研究Java.Lang.NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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