【问题标题】:Getting IndexOutOfBound exception during setting a text to TextView在将文本设置为 TextView 期间获取 IndexOutOfBound 异常
【发布时间】:2018-07-31 14:37:57
【问题描述】:

我的应用程序在我的测试设备和大多数用户(也许)中运行良好,但我在我的游戏控制台帐户中收到崩溃报告,我不明白问题出在哪里。我附上了堆栈跟踪和代码的屏幕截图。

这是行号。 60,AdhynikYugDetails.java,如堆栈跟踪中所述:

tv_detailed_description.setText(R.string.jatiyatabadi_andolan_details);

这样的行很多,但只有这行导致崩溃:Stack traces

这是完整的块:

else if (getIntent().getBooleanExtra("jatiyatabadi_andolan", AdhunikYug.jatiyatabadi_andolan)) {
        tv_heading.setText(R.string.jatiyatabadi_andolan);
        tv_detailed_description.setText(R.string.jatiyatabadi_andolan_details); //line no 60

        AdhunikYug.jatiyatabadi_andolan = false;
    } 

会不会是字符串有问题?我应该发布它吗?这是一条长长的孟加拉语字符串。

【问题讨论】:

  • 这个字符串有多长?
  • 它是一个简短的问题答案类型字符串,有245个问题和答案

标签: java android textview indexoutofboundsexception


【解决方案1】:

这样做:-

tv_detailed_description.setText(getResources().getString(R.string.jatiyatabadi_andolan_details));

【讨论】:

  • 感谢@Raj 的回复。你能解释一下吗?该应用程序在我的测试设备 Lenovo K3 Note 上运行良好,可能适用于大多数用户。
  • 再次感谢@Raj,我是说我的应用程序从一开始就运行良好。如果问题得到解决,我一定会接受你的回答。现在有没有办法在不上传新版本的情况下检查它?抱歉耽搁了。
  • 这很简单:您所做的是将字符串 Resource 设置为文本。它可能适用于某些设备,但更安全的方法是像@Raj 所说的那样,通过 android 工具提取该资源并以 String 的形式传递给 setText 方法
  • @Raj 方法 setText() 有 6 个实现:public final void setText(CharSequence text)public void setText(CharSequence text, BufferType type)private void setText(CharSequence text, BufferType type, boolean notifyBefore, int oldlen)public final void setText(char[] text, int start, int len)public final void setText(@StringRes int resid)public final void setText(@StringRes int resid, BufferType type)
猜你喜欢
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
  • 2016-02-23
  • 1970-01-01
  • 2017-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多