gpt4 book ai didi

java - 如何在android中搜索字符串数组?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:23:25 25 4
gpt4 key购买 nike

<分区>

我想在一个数组中搜索,我的代码是这样的:

public class A
{
public String [] Names;
public A( List<String> listSp)
{
Names = new String[listSp.size()];
listSp.toArray(Names);
}
public int numberOfState(String s)
{

int counter = 0;
while (Names[counter] != s)
{
counter ++;
}
return counter;
}

并在此代码中使用 A 类:

public class Main extends Activity
{
...
List<String> l = new ArrayList<String>();
l.add("a");
l.add("b");
A objA = new A(l);
int i = objA.numberOfState("b");
...
}

并且在运行应用程序和使用这部分时,一直显示这个错误:

Unfortunately,Main has been stopped

我该怎么做?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com