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

<?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和错误仍然存在,我一定是做了根本性的错误为这样一个基本的布局,导致这一点。

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


当前回答

尽量避免在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"或最好不要使用它,如果不需要。有时键盘卡住,在一些设备中得到错误。

其他回答

**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("")
            }
            Log.e("text_change","============"+s.toString())
        }
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
        }
    })

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

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

要解决这个问题,只需在你的AndroidManifest.xml文件中添加android:usesCleartextTraffic="true",该文件位于..\app\src\main\AndroidManifest.xml,就像下面这样…

检查是否有任何元素,如按钮或文本视图复制(复制两次)在屏幕上遇到。我没有注意到这件事,也不得不面对同样的问题。