小编dro*_*hef的帖子

初始化ArrayList <ArrayList <Int >>,大小为kotlin

我试图在构造函数中初始化一个大小的列表.但是我的列表大小为0.

val seqList = ArrayList<ArrayList<Int>>(N) // This has the Problem
val queries = ArrayList<Query>(Q) // This works like a charm
Run Code Online (Sandbox Code Playgroud)

我有两个NQ设置为来自用户的非零输入让我们说 N = 100Q = 100

调试我的代码时,我发现了,queries.size() = 100但是seqList.size() = 0

我的假设是不正确的,也seqList应该用N ArrayList<Int>对象初始化.

java arrays list dynamic-arrays kotlin

9
推荐指数
1
解决办法
3472
查看次数

ArrayIndexOutOfBoundsExecption:安卓

我是一名新手Android开发者.我试图从用户使用和编辑文本框获取文本输入,然后将该文本转换为字符串,然后转换为大小为4的字符数组.我已经存储了一个大小为4的数组,它包含值.我想比较两个数组并根据结果执行任务.

我不知道为什么我得到ArrayIndexOutOfBoundsExecption

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newgame);

    Button submit = (Button) findViewById(R.id.guess);



    EditText guess = (EditText) findViewById(R.id.editText1);


    boolean c=false;

    char[] guessword;
    char[] appword = {'T', 'R', 'U', 'E'};
    guessword = guess.getText().toString().toCharArray();


    for(int i=0;i<appword.length;i++)
    {
        if(guessword[i]==appword[i])
        {
            c=true;
        }
        else
        {
            c=false;
        }
    }

    final boolean correct=c;        


    submit.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            if(correct){
                startActivity(new Intent(Newgame.this, Win.class));
            }
            else{
                startActivity(new Intent(Newgame.this, Loose.class));
            }

        }
    });



}
Run Code Online (Sandbox Code Playgroud)

}

java arrays android indexoutofboundsexception

2
推荐指数
1
解决办法
96
查看次数

创建一个在所有应用程序上都可见的视图

我想创建一个即使我的应用程序不在前台(To Toast)也始终可见的视图.此外,我还可以在任务完成时隐藏此视图.例如:类似于android 4.0中CPU使用率的视图,它在设备左上角的所有屏幕上都可见

android

2
推荐指数
1
解决办法
557
查看次数