1

最近、Android 4.1.1 を実行している ASUS Transformer Pad TF700T のユーザーの 1 人からクラッシュ レポートを受け取りました。TextView について同様のクラッシュ レポートを見たことがありますが、通常はカスタム コードに関連付けられています。これは WebView 用であり、このクラッシュに直接関連して私が書いたコードはないようです。

これ以上の情報はありませんが、ユーザーが Web ビュー内に表示された編集ボックスをクリックしたときに発生する可能性があります (Web ビューに表示されるページの URL とコンテンツはわかっています)。これにアプローチする方法がわかりません...

java.lang.IndexOutOfBoundsException: setSpan (-4 ... -4) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1021)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
at android.text.Selection.setSelection(Selection.java:76)
at android.view.inputmethod.BaseInputConnection.setSelection(BaseInputConnection.java:497)
at android.webkit.WebViewClassic$WebViewInputConnection.setSelection(WebViewClassic.java:482)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:288)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

3

For some reason, it appears a text selection with a negative start index is attempted to be made. At least, that's what the stracktrace tells you.:

Line 67 in Selection:

text.setSpan(SELECTION_START, start, start, Spanned.SPAN_POINT_POINT|Spanned.SPAN_INTERMEDIATE);

So apparently start has a value of -4. It gets passed in as a parameter and if you follow the trace back up, that value is parsed out of a DO_SET_SELECTION message.

I'm guessing that the error could occur if the text that's selected in the WebView changes while the selection is taking place, but without any extra details that's going to be difficult to confirm.

Interestingly, BaseInputConnection.setSelection(int, int) does contain an interesting code comment that makes my earier guess more plausible:

/**
 * The default implementation changes the selection position in the
 * current editable text.
 */
public boolean setSelection(int start, int end) {
    if (DEBUG) Log.v(TAG, "setSelection " + start + ", " + end);
    final Editable content = getEditable();
    if (content == null) return false;
    int len = content.length();
    if (start > len || end > len) {
        // If the given selection is out of bounds, just ignore it.
        // Most likely the text was changed out from under the IME,
        // the the IME is going to have to update all of its state
        // anyway.
        return true;
    }
    if (start == end && MetaKeyKeyListener.getMetaState(content,
            MetaKeyKeyListener.META_SELECTING) != 0) {
        // If we are in selection mode, then we want to extend the
        // selection instead of replacing it.
        Selection.extendSelection(content, start);
    } else {
        Selection.setSelection(content, start, end);
    }
    return true;
}

There's an out of bounds check, but only on the upper bound, not the lower bound. Adding a check for start < 0 || end < 0 would probably prevent the IndexOutOfBoundsException as shown in your stracktrace from being thrown. Unfortunately that's probably not really going to help you, as it's unlikely you're going to be able to control the event flow from the WebView...

于 2012-12-24T02:49:52.253 に答える