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:contentDescription="content desc"
    android:orientation="vertical" >

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

The Activity class contains the following:

public class TestActivity extends Activity {
  public void onCreate(Bundle savedInstanceState) {

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

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?

Solution 1

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.

Solution 2

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! :)

Solution 3

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.


Hope this helps!

Solution 4

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).

Solution 5

Try using the default Android keyboard it will disappear

Solution 6

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".

Solution 7

This worked for me...on every device

        android:hint="Enter Address, City or Zip Code"

In Java code:

mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if(actionId == EditorInfo.IME_ACTION_SEARCH
                    || actionId == EditorInfo.IME_ACTION_DONE
                    || keyEvent.getAction() == KeyEvent.ACTION_DOWN
                    || keyEvent.getAction() == KeyEvent.KEYCODE_ENTER){

                //execute our method for searching

            return false;

Solution 8

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.

Solution 9

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.

Solution 10

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


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)

Solution 11

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.

Solution 12

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.

Solution 13

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.

Solution 14

I had the same problem but with a listView.... i solved it because i was using a wrong R.id.listView that list View needed to have a value, in my case it was strings that i saved on listView2... so the right code was R.id.listView2

Solution 15

I had the same problem then i fixed it by following code!

  text = (EditText)findViewById(R.id.TextVoiceeditText); 

Solution 16

this error also occurs due to changed API URL. try hitting the URL you are using in postman and c if it's working properly. rechecking the APIs solved my problem

Solution 17

try avoiding use of view in xml design.I too had the same probem but when I removed the view. its worked perfectly.

like example:

                android:textColor="#fff" />

                android:background="#f9d7db" />

also check and try changing by trial and error android:inputType="number" to android:inputType="text" or better not using it if not required .Sometimes keyboard stuck and gets error in some of the devices.

Solution 18

In my case, the EditText fields with inputType as text / textCapCharacters were casing this error. I noticed this in my logcat whenever I used backspace to completely remove the text typed in any of these fields.

The solution which worked for me was to change the inputType of those fields to textNoSuggestions as this was the most suited type and didn't give me any unwanted errors anymore.

Solution 19

in my case i click on recent apps shortcut on my cell phone and close all apps. This solution always work for me, because this error not related to code.

Solution 20

**DONT PUT SET TEXT IN TEXT WATCHER**etSearch.addTextChangedListener(object : TextWatcher {
        override fun afterTextChanged(s: Editable) {
            visibleResultList = false
            if (s.toString().length != 0) {
                getSearchSuggetion(no_of_rec, 0, s.toString())
            } else {
               // etSearch.setText("")
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {

Solution 21

To solve this problem just add android:usesCleartextTraffic="true" in your AndroidManifest.xml file which is at ..\app\src\main\AndroidManifest.xml just like bellow...