Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有按钮的ArrayList的ResourcesNotFoundException_Java_Android_Arraylist_Scroll - Fatal编程技术网

Java 带有按钮的ArrayList的ResourcesNotFoundException

Java 带有按钮的ArrayList的ResourcesNotFoundException,java,android,arraylist,scroll,Java,Android,Arraylist,Scroll,我需要创建一个充满按钮的ArrayList,它将链接到水平滚动布局。将按钮文本插入ArrayList后,尝试更改按钮文本时出现ResourceNotFound错误: public class Dictionary extends Activity implements Runnable, OnClickListener { //Candidates candidatesScrollView = (HorizontalScrollView) findViewById(R.id.ac

我需要创建一个充满按钮的ArrayList,它将链接到水平滚动布局。将按钮文本插入ArrayList后,尝试更改按钮文本时出现ResourceNotFound错误:

public class Dictionary extends Activity implements Runnable, OnClickListener {
    //Candidates
    candidatesScrollView = (HorizontalScrollView) findViewById(R.id.activity_dictionary_horizontalScrollView1);

    candidatesButtons = new ArrayList<Button>();
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button1));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button2));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button3));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button4));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button5));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button6));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button7));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button8));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button9));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button10));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button11));
    candidatesButtons.add((Button) findViewById(R.id.activity_dictionary_horizontalscrollview1_button12));
    for(int i = 0; i < candidatesButtons.size(); i++)
        ((Button) candidatesButtons.get(i)).setOnClickListener(this);

    (...)
}
公共类字典扩展活动实现可运行的OnClickListener{
//候选人
CandidateScrollView=(HorizontalScrollView)findViewById(R.id.activity\u dictionary\u HorizontalScrollView 1);
candidatesButtons=newArrayList();
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮1));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u button2));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮3));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮4));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮5));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮6));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮7));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮8));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮9));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u按钮10));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u button11));
候选按钮。添加((按钮)findViewById(R.id.activity\u dictionary\u horizontalscrollview1\u button12));
对于(int i=0;i
我尝试在此方法内更改该属性:

private void recognize() {

    (...)

    byte buffer[];
    buffer = RecogEngine.setResult(0); // and set the remaining data to engine
    try {
        candidatesString = new String(buffer, "UTF-8");     
        Button b;
        for (int i = 0; i < candidatesString.length(); i++)
            candidatesButtons.get(i).setText(candidatesString.charAt(i));
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    (...)
}
private void recognize(){
(...)
字节缓冲区[];
buffer=RecogEngine.setResult(0);//并将剩余数据设置为engine
试一试{
CandidateString=新字符串(缓冲区,“UTF-8”);
按钮b;
对于(int i=0;i

我做错了什么?

您的for循环更改按钮字符串使用candidateString长度作为循环增量,因此如果长度超过12,它将抛出该异常,因为您只有12个按钮

我不知道您试图在for循环中实现的业务逻辑。但是下面的代码应该适用于12个按钮。或者需要限制for循环的最小值(12或字符串长度)

for(int i=0;i
我不太确定,但是可能会对java处理char和int有一些混淆,没有经过深入的学习,您的代码
candidatesButtons.get(I).setText(candidatesString.charAt(I))
may要求java搜索字符串资源对象,请尝试使用
candidatesButtons.get(i).setText(string.valueOf(candidatesString.charAt(i))
。它可以工作。如果有人知道为什么以前的解决方案不起作用,我会非常高兴知道它@Chor WaiChun您应该对此进行更多解释,并将其作为解决方案发布。请检查更新的问题,这是一个很好的建议,但不是错误的情况。请检查以上内容。
for (int i = 0; i < candidatesString.length(); i++)
            if(i < 12)
                candidatesButtons.get(i).setText(candidatesString.charAt(i));
    }