I am getting the setspan error setspan starts before 0 at
up vote
1
down vote
favorite
I am getting the following error don't know what's wrong with my code. When its bold and italic then italic text sometimes removed and some time not and then get this error.
2018-11-10 19:34:03.032 16997-16997/com.pilum.apps.primalnotes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pilum.apps.primalnotes, PID: 16997
java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:672)
at com.apps.primalnotes.Fragments.EditorFragment.italicText2(EditorFragment.java:393)
at com.apps.primalnotes.Fragments.EditorFragment.access$300(EditorFragment.java:48)
at com.apps.primalnotes.Fragments.EditorFragment$5.onClick(EditorFragment.java:129)
at android.view.View.performClick(View.java:6877)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
private void italicText2(){
boolean italicExists = false;
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
if (!italicExists) {
Log.d("Tag", "italic section entered");
if (styleSpans.length > 0)
int lastSpanEnd = 0;
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart > lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), lastSpanEnd, spanStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "if italic");
lastSpanEnd = spanEnd;
str.removeSpan(styleSpan);
if (oldStyle == Typeface.BOLD)
str.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "Bold and Italic");
else
**str.setSpan(new StyleSpan(Typeface.ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);**
Log.d("TAG", "else italic");
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "oldstyle italic");
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "old style end italic");
if (selEnd != lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
java spannablestring
add a comment |
up vote
1
down vote
favorite
I am getting the following error don't know what's wrong with my code. When its bold and italic then italic text sometimes removed and some time not and then get this error.
2018-11-10 19:34:03.032 16997-16997/com.pilum.apps.primalnotes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pilum.apps.primalnotes, PID: 16997
java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:672)
at com.apps.primalnotes.Fragments.EditorFragment.italicText2(EditorFragment.java:393)
at com.apps.primalnotes.Fragments.EditorFragment.access$300(EditorFragment.java:48)
at com.apps.primalnotes.Fragments.EditorFragment$5.onClick(EditorFragment.java:129)
at android.view.View.performClick(View.java:6877)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
private void italicText2(){
boolean italicExists = false;
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
if (!italicExists) {
Log.d("Tag", "italic section entered");
if (styleSpans.length > 0)
int lastSpanEnd = 0;
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart > lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), lastSpanEnd, spanStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "if italic");
lastSpanEnd = spanEnd;
str.removeSpan(styleSpan);
if (oldStyle == Typeface.BOLD)
str.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "Bold and Italic");
else
**str.setSpan(new StyleSpan(Typeface.ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);**
Log.d("TAG", "else italic");
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "oldstyle italic");
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "old style end italic");
if (selEnd != lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
java spannablestring
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am getting the following error don't know what's wrong with my code. When its bold and italic then italic text sometimes removed and some time not and then get this error.
2018-11-10 19:34:03.032 16997-16997/com.pilum.apps.primalnotes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pilum.apps.primalnotes, PID: 16997
java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:672)
at com.apps.primalnotes.Fragments.EditorFragment.italicText2(EditorFragment.java:393)
at com.apps.primalnotes.Fragments.EditorFragment.access$300(EditorFragment.java:48)
at com.apps.primalnotes.Fragments.EditorFragment$5.onClick(EditorFragment.java:129)
at android.view.View.performClick(View.java:6877)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
private void italicText2(){
boolean italicExists = false;
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
if (!italicExists) {
Log.d("Tag", "italic section entered");
if (styleSpans.length > 0)
int lastSpanEnd = 0;
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart > lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), lastSpanEnd, spanStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "if italic");
lastSpanEnd = spanEnd;
str.removeSpan(styleSpan);
if (oldStyle == Typeface.BOLD)
str.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "Bold and Italic");
else
**str.setSpan(new StyleSpan(Typeface.ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);**
Log.d("TAG", "else italic");
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "oldstyle italic");
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "old style end italic");
if (selEnd != lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
java spannablestring
I am getting the following error don't know what's wrong with my code. When its bold and italic then italic text sometimes removed and some time not and then get this error.
2018-11-10 19:34:03.032 16997-16997/com.pilum.apps.primalnotes E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pilum.apps.primalnotes, PID: 16997
java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1314)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:672)
at com.apps.primalnotes.Fragments.EditorFragment.italicText2(EditorFragment.java:393)
at com.apps.primalnotes.Fragments.EditorFragment.access$300(EditorFragment.java:48)
at com.apps.primalnotes.Fragments.EditorFragment$5.onClick(EditorFragment.java:129)
at android.view.View.performClick(View.java:6877)
at android.view.View$PerformClick.run(View.java:26069)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
private void italicText2(){
boolean italicExists = false;
Spannable str = texto.getText();
int selStart = texto.getSelectionStart();
int selEnd = texto.getSelectionEnd();
StyleSpan styleSpans = texto.getText().getSpans(selStart, selEnd, StyleSpan.class);
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (selEnd > selStart)
if (oldStyle == Typeface.ITALIC)
str.removeSpan(styleSpan);
italicExists = true;
if (oldStyle == Typeface.BOLD_ITALIC)
str.setSpan(new StyleSpan(Typeface.BOLD), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
italicExists = false;
if (!italicExists) {
Log.d("Tag", "italic section entered");
if (styleSpans.length > 0)
int lastSpanEnd = 0;
for (StyleSpan styleSpan : styleSpans)
int oldStyle = styleSpan.getStyle();
int spanStart = str.getSpanStart(styleSpan);
int spanEnd = str.getSpanEnd(styleSpan);
if (spanStart > lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), lastSpanEnd, spanStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "if italic");
lastSpanEnd = spanEnd;
str.removeSpan(styleSpan);
if (oldStyle == Typeface.BOLD)
str.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "Bold and Italic");
else
**str.setSpan(new StyleSpan(Typeface.ITALIC), spanStart, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);**
Log.d("TAG", "else italic");
if (spanStart < texto.getSelectionStart())
str.setSpan(new StyleSpan(oldStyle), spanStart, selStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "oldstyle italic");
if (spanEnd > texto.getSelectionEnd())
str.setSpan(new StyleSpan(oldStyle), selEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Log.d("TAG", "old style end italic");
if (selEnd != lastSpanEnd)
str.setSpan(new StyleSpan(Typeface.ITALIC), selStart, selEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
java spannablestring
java spannablestring
asked Nov 11 at 0:42
S Shah
98110
98110
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244829%2fi-am-getting-the-setspan-error-setspan-starts-before-0-at%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown