我使用了这个belove代码,但它给了我类似Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference'
的错误
我的代码是:
public void SetBulletText(EditText myEditText, string text) {
string[] lines = TextUtils.Split(text, "/n");
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
string line = null;
for (int index = 0; index < lines.Length; ++index) {
line = lines[index];
int length = spannableStringBuilder.Length();
spannableStringBuilder.Append(line);
if (index != lines.Length - 1) {
spannableStringBuilder.Append("\n");
} else if (TextUtils.IsEmpty(line)) {
spannableStringBuilder.Append("\u200B");
}
spannableStringBuilder.SetSpan(new BulletSpan(30), length, length + 1, SpanTypes.MarkPoint);
}
myEditText.Text = spannableStringBuilder.ToString();
}
您的lines数组被视为空对象,因为没有正确将数据放入数组中。现在,您可能正在覆盖一个内存地址。