我有以下布局(实际上是空的):

<?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>

Activity类包含以下内容:

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

当我在我的移动设备上运行这个,我得到以下错误:

SpannableStringBuilder
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

我已经尝试了这个与没有TextView和错误仍然存在,我一定是做了根本性的错误为这样一个基本的布局,导致这一点。

有人有什么想法吗,我怎么才能让这个加载没有错误?


当前回答

这对我很管用……在每个设备上

    <EditText
        android:maxLines="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="15sp"
        android:layout_centerVertical="true"
        android:textColor="#000"
        android:id="@+id/input_search"
        android:background="@null"
        android:inputType="text"
        android:hint="Enter Address, City or Zip Code"
        android:imeOptions="actionSearch"
        />

在Java代码中:

mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        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;
        }
    });

其他回答

在你的安卓手机上转到: 设置->应用程序管理器->全部->三星键盘,然后点击“清除缓存” (删除此应用程序收集的所有数据)。

看看你的代码,我不知道为什么你会得到这个错误,但我有同样的错误,但与EditText字段。

改变android:inputType=“文本”(或任何其他inputType文本变体)到android:inputType=“textnosuggestion”(或android:inputType=“textEmailAddress| textnosuggestion”,例如)为我修复了它。

您还可以在代码中使用类似于

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

看起来Android默认假设EditText字段会有建议。如果没有,就会出错。不是100%相信这个解释,但上面提到的变化为我解决了这个问题。

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

希望这能有所帮助!

当我从网上复制一些文本时,我也遇到了这个问题。我的解决方案是在做任何进一步处理之前修剪文本/删除格式。

我也遇到过同样的问题。我几乎浪费了几周的时间来解决这个问题。 最后,我对自己产生了怀疑,并试图通过复制和粘贴一些启动文件,如SplashScreen和LoginScreen,来创建另一个项目。

但同样的代码,我仍然得到SPAN_EXCLUSIVE_EXCLUSIVE。

然后我已经从启动画面中删除了处理程序代码,并再次尝试,哇,它的工作。 我没有得到SPAN_EXCLUSIVE_EXCLUSIVE问题在logcat。

我在想,为什么会这样?直到时间没有得到任何其他解决方案,但从启动画面删除处理程序,它是工作的。

如果问题已经解决,请尝试在这里更新。

这对我很管用……在每个设备上

    <EditText
        android:maxLines="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="15sp"
        android:layout_centerVertical="true"
        android:textColor="#000"
        android:id="@+id/input_search"
        android:background="@null"
        android:inputType="text"
        android:hint="Enter Address, City or Zip Code"
        android:imeOptions="actionSearch"
        />

在Java代码中:

mSearchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        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;
        }
    });