Error:SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

I have googled this to death but cannot find the answer anywhere.

I have the following layout (virtually empty):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/set_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:contentDescription="content desc"
    android:orientation="vertical" >

    <TextView android:id="@+id/text"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Hello, I am a TextView" />
</LinearLayout>

The Activity class contains the following:

public class TestActivity extends Activity {
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);   
  }
}

When i run this on my mobile device i get the following error:

SpannableStringBuilder
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

I have tried this with and without the TextView and the error still remains, i must be doing something fundamentally wrong for such a basic layout to cause this. Does anyone have any ideas on how i can get this to load without the error?

Thanks in advance....

share | improve this question
 
 
Examine LogCat and look at the stack trace associated with your error. If it indeed is from this app, post the entire stack trace as an edit to your question. Also, I would get rid of android:contentDescription fromLinearLayout, as that container is not focusable and therefore the description will not be used AFAIK. –  CommonsWare  Dec 2 '12 at 21:37 
1  
Thanks for your response. Unfortunately there is no stack trace for this error, the output is exactly as i have posted above, but the application field in LogCat does point to my application. I have debugged the code and stepped through each line with no error being thrown, so it must be somewhere in the Android code that is expecting something that isn't there. –   DMac  Dec 3 '12 at 10:43 
 
I would like to know how to avoid this annoying error too, without removing/disabling any feature for the end user. –   android developer  Apr 20 '13 at 10:46
1  
I reset the phone to factory settings and it went away, after trying the 'samsung keyboard fix' which didn't seem to do the trick for me... –   Shark  Sep 5 '13 at 15:42
 
Perhaps it isn't a problem at all, but after upgrading to Android 4.1.1 I'm seeing a lot of errors in the logs like this one. SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length –   Sagar Raiyani  Sep 6 '13 at 11:25

13 Answers

I have run into the same error entries in LogCat. In my case it's caused by the 3rd party keyboard I am using. When I change it back to Android keyboard, the error entry does not show up any more.

share | improve this answer
 
66  
This is the most probable cause of this issue as there is also a bug report for SwiftKey:support.swiftkey.net/forums/116693-2-bug-reports/suggestions/… –   Rabi  Feb 18 '13 at 12:18
 
mmm.. very interesting.. –   abbood  Jul 27 '13 at 14:59
1  
thanks @Rabi, even i switched to swiftkey and started getting the errror. –   Maulik Sheth  Sep 4 '13 at 11:50
2  
I get the error while using stock Android keyboard on a Nexus 7 (2012 edition, running 4.3) –   Tom  Nov 7 '13 at 21:06
2  
Google's keyboard is also causing this error. –   kevin  Mar 21 at 0:12

Because the error you're getting is not related to an EditText, then it's not related to your keyboard.

The errors you are getting are not a result of your code; you probably are testing on a Samsung device that has Samsung's TouchWiz.

I had the same errors, then I tested on a Nexus S (also by Samsung, but pure Android OS without TouchWiz) and I didn't get this error.

So, in your case, just ignore these errors while testing on a device! :)

share | improve this answer
 
 
It is your keyboard, probably the keyboard of TouchWiz in your case. I have the same errors on a Nexus 4 with Swiftkey, if I choose the default Android keyboard the errors are gone. –   Dante  May 6 '13 at 23:46
 
Keyboards can definitely lead to this error, but in the case where the keyboard is not used or called, i.e. in the case where there are no EditText's, I don't see how the keyboard can be the source of the problem. When I switch between two different activities, both without EditText, I keep getting the error every time I go to one of these activities. –   Karim  May 7 '13 at 3:48
2  
I agree with Cookiki, the errors are because of Samsung TouchWiz, and its not causing any problems other than spewing errors in logcat. So will be ignoring them –   user2566490  Aug 2 '13 at 18:39
 
We can't just ignore errors because it only happens on a TouchWiz, the least is reporting to samsung that there's a problem with touchwiz. –   Sojurn  Oct 31 '13 at 6:17
1  
I can most certainly occur without it being related to an EditText. I had this error when displaying a PreferenceFragment with some headers - no textboxes or anything of the sort. On every change from one PreferenceFragment I got two of these error messages. Switched from "Samsung Keyboard" to "Smart Keyboard Pro" and the error messages stopped. –   BadCash  Mar 15 at 11:49

Looking at your code, I'm not sure why you're getting that error, but I had this same error but with EditText fields.

Changing android:inputType="text" (or any of the other inputType text variations) to android:inputType="textNoSuggestions" (or android:inputType="textEmailAddress|textNoSuggestions", for example) fixed it for me.

You can also set this in Code with something like

mInputField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

Looks like Android assumes by default that EditText fields will have suggestions. When they don't, it errors. Not 100% confident in that explanation, but the above mentioned changes fixed it for me.

http://developer.android.com/reference/android/text/Spanned.html#SPAN_EXCLUSIVE_EXCLUSIVE

Hope this helps!

share | improve this answer
 
 
Thanks for this. But even with the TextView removed and only the layout present i get the error. It is very strange. –   DMac  Dec 4 '12 at 11:41
 
Removing the contentDescription from the LinearLayout doesn't help? –   tim  Dec 6 '12 at 21:16
1  
No unfortunately not. Although with further investigation the error does only seem to display on Samsung Devices. –   DMac  Dec 8 '12 at 9:51
 
Solution worked for me! –   Markus Proske  Dec 29 '12 at 22:34
 
This is not working for me. –   NagarjunaReddy  Jul 11 at 8:26

Try using the default Android keyboard it will disappear

share | improve this answer
 
 
how to use default keyboard. –   NagarjunaReddy  Jul 11 at 13:59
1  
You have to change it in phone input settings. If you didn't change it, you should have default keyboard. It's quite funny solution with that default keyboard, but it works for me.. : p –   Krystian  Jul 24 at 9:02
 
The default Android keyboard also has the problem (I have it on a Nexus 5) –   Yoann Hercouet  Dec 8 at 8:42

On your android phone go to:
settings -> application manager -> all -> samsung keyboard and then click on "clear cache"
(delete all data collected by this application).

share | improve this answer
 
 
man u saved my life today! –   Wasif Khalil  Dec 16 '13 at 18:13
 
Wow I had 68 MB of stuff cached by that app. :O –   XåpplI'-I0llwlg'I -  Apr 22 at 10:42
 
i have accr tablet hot solve this issue. –   NagarjunaReddy  Jul 11 at 14:00

Make clear you have pass a value in your MainAcitivity for the following methods onCreateOptionsMenu and onCreate

In some cases, the developer deletes the "return super.onCreateOptionsMenu(menu)" statement and changed to "return true".

share | improve this answer
 

I had the same warning and found that removing an unused @id got rid of the warning. For me it was obvious as the @id was associated with a growing list of textViews linked to a database, so there was a warning for each entry.

share | improve this answer
 

Masood Moshref is right, this error occur because the option menu of Menu is not well prepared by lacking "return super.onCreateOptionsMenu(menu)" in onCreate() method.

share | improve this answer
 

To try to debug this error, first go to your android terminal / console and execute this command:

ps | grep THE_ERROR_PID_YOU_GET_(IT_IS_A_NUMBER)

then if the output comes out as your app... it is your app causing the error. Try to look for empty Strings that you pass into the layout.

I had this exact same problem and it was my fault as I was passing an empty String into my layout. After changing the "" to " " this error went away.

If you don't get your app from the console output, then it is something else causing it (probably, as others said, the android keyboard)

share | improve this answer
 

I have faced the same issue. I almost wasted almost couple of weeks to resolved this issue. Finally I had on doubt on myself and tried to create another project by copy and paste some startup files like SplashScreen & LoginScreen.

But with the same code still i was getting SPAN_EXCLUSIVE_EXCLUSIVE.

Then i have removed the handler code from splash screen and tried again and Wow its working. I am not getting SPAN_EXCLUSIVE_EXCLUSIVE issue in logcat.

I wondering, why it is? till the time did not get any other solution but by removing handler from splash screen it is working.

Try and update here if it is resolved or not.

share | improve this answer
 
 
i will try your solution brother –   Zala Janaksinh  Nov 13 '13 at 12:09

And I also decided write my opinion. Sometimes It is happened, if you forgot to add all your activities to Manifest file.

share | improve this answer
 

Check if you have any element such as button or text view duplicated (copied twice) in the screen where this encounters. I did this unnoticed and had to face the same issue.

share | improve this answer
 

I ran into this problem too when I copied some text from the Internet. My solution is to trim the text/remove formatting before doing any further processing.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值