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

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

希望这能有所帮助!

其他回答

我在LogCat中遇到了相同的错误条目。在我的情况下,这是由我正在使用的第三方键盘引起的。当我把它改回Android键盘时,错误条目不再显示。

我遇到了同样的警告,发现删除一个未使用的@id可以消除警告。对我来说,这是显而易见的,因为@id与链接到数据库的textview的一个不断增长的列表相关联,所以每个条目都有一个警告。

我有同样的问题,但与listView....我解决了它,因为我使用了一个错误的R.id.listView列表视图需要有一个值,在我的情况下,它是字符串,我保存在listView2…所以正确的代码是R.id.listView2

尽量避免在XML设计中使用view。我也有同样的问题,但当我删除视图。它工作得很完美。

像例子:

             <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"                   
                android:hint="Username"
                android:inputType="number"                   
                android:textColor="#fff" />

            <view
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#f9d7db" />

也检查并尝试通过反复试验改变android:inputType="number"到android:inputType="text"或最好不要使用它,如果不需要。有时键盘卡住,在一些设备中得到错误。

Masood Moshref是对的,这个错误发生是因为菜单的选项菜单没有做好准备,在onCreate()方法中缺少“返回super.onCreateOptionsMenu(菜单)”。