NullPointerException异常的SuggestionSpan [英] NullPointerException at SuggestionSpan

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

问题描述

我得到一个NullPointerException异常的SuggestionSpan。 (堆栈跟踪包括下文)。由于堆栈跟踪不包含任何对我的code,我完全不知道从哪里开始调试。

I am getting a NullPointerException at SuggestionSpan. (Stack trace included below). As the stack trace does not include any of my code, I have absolutely no idea where to start debugging.

该错误可每当我preSS空间(或者选择一个单词),而使用一个EditText再现。我试过多个键盘,包括股票Android的一个,但出现同样的错误。

The error can be reproduced whenever I press space (or select a word) while using an EditText. I tried multiple keyboards including the stock Android one but the same error appears.

FATAL EXCEPTION: main
java.lang.NullPointerException
at android.text.style.SuggestionSpan.<init>(SuggestionSpan.java:128)
at android.text.style.SuggestionSpan.<init>(SuggestionSpan.java:101)
at android.widget.SpellChecker.createMisspelledSuggestionSpan(SpellChecker.java:392)
at android.widget.SpellChecker.onGetSuggestions(SpellChecker.java:300)
at android.view.textservice.SpellCheckerSession.handleOnGetSuggestionsMultiple(SpellCheckerSession.java:198)
at android.view.textservice.SpellCheckerSession.access$000(SpellCheckerSession.java:86)
at android.view.textservice.SpellCheckerSession$1.handleMessage(SpellCheckerSession.java:112)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

编辑:我只能重现错误在我的Nexus S采用4.0.3,但不能在仿真器与其他版本的操作系统。怪异。

I can only reproduce the error on my Nexus S with 4.0.3, but not on emulators with other OS versions. Weird.

编辑2:奇怪的事情发生了!我只是拖着一个EditText到另一个活动,同样的事情发生。没有code被连接到它,也没有给它的任何XML的改变。

EDIT 2: Strange thing happened! I just dragged an EditText into another activity and the same thing happens. No code is attached to it nor any XML changes made to it.

推荐答案

在连日侦查,事实证明,getResources()。getConfiguration()。区域设置为空。我不知道这是否是特定于某些版本的Andr​​oid的问题/某些设备(我的是Nexus S的运行4.0.3)。

After days of investigation, it turns out that getResources().getConfiguration().locale is null. I am not sure if it is a problem specific to some versions of Android / some devices (mine is Nexus S running 4.0.3).

但我通过检查活动的构造函数的工作解决此问题(因为给予SuggestionSpan的背景是我的活动)的区域是否为空,然后将其设置为默认的,如果它是。

But I worked around this issue by checking in the constructor of the Activity (since the context given to the SuggestionSpan is my Activity) whether the locale is null, and then set it to the default one if it is.

    // to prevent a weird bug where locale is null
    Configuration config = getResources().getConfiguration();
    if (config.locale == null)
        config.locale = Locale.getDefault();

这就是我所做的。我敢肯定它不是,虽然最好的办法。任何人有任何更多的想法?

That's what I did. I am quite sure it's not the best way though. Anyone have any more ideas?

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

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