java android字符串和整数函数不起作用

java android字符串和整数函数不起作用,java,android,string,function,integer,Java,Android,String,Function,Integer,嗨,我不确定这是否是Java或Java的问题,但最近我的代码已经停止工作。我只是改变了一些事情,比如分配新的变量来存储东西。我的程序接受一个多维字符串数组,应该返回一个新的空数组 public void makebuttons(final int n, String equals) { //does lots of widget functions and id assignments String[] items=getArray(Integer.parseInt(data.e

嗨,我不确定这是否是Java或Java的问题,但最近我的代码已经停止工作。我只是改变了一些事情,比如分配新的变量来存储东西。我的程序接受一个多维字符串数组,应该返回一个新的空数组

public void makebuttons(final int n, String equals) {
    //does lots of widget functions and id assignments
    String[] items=getArray(Integer.parseInt(data.equnits.substring(n*3, n*3+1)));
    unitvalues[n]=Integer.parseInt(data.equnits.substring(n*3, n*3+1));
    ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item, items);
    //does more code
}
public static String[] getArray(int selection) {
    String[] result;//stores the new array
    int x=0,j=0 ,ulength = data.units[0].length;//ints used
    String temp="";
    while(j < ulength && temp!=null) {
        temp= data.units[selection][j][0];    //find the actual array length
        j++;
    }
    if(j==ulength)j--;
    result = new String[j+1];//initalise array from check
    for(x=0; x<=j; x++) { //add data to array
        result[x]=data.units[selection][x][0];
    }
    return result;//return corrected array
}
public void makebutton(最终整数n,字符串等于){
//有很多小部件功能和id分配
String[]items=getArray(Integer.parseInt(data.equits.substring(n*3,n*3+1));
unitvalues[n]=Integer.parseInt(data.equits.substring(n*3,n*3+1));
ArrayAdapter aa=新的ArrayAdapter(这个,android.R.layout.simple\u微调器\u项,项);
//做更多的代码
}
公共静态字符串[]getArray(整数选择){
字符串[]结果;//存储新数组
int x=0,j=0,ulength=data.units[0].length;//使用的int
字符串temp=“”;
while(j对于(x=0;x如果没有更多信息,我无法帮助您解决第一个问题,但这似乎是您的第二个问题:

函数子字符串包含第一个参数,不包含第二个参数。因为您只在n*3中添加1,所以只能得到一个字符

尝试使用:

substring(n*3, n*3+2)
编辑:

添加上面我的评论中的更新代码:

while(j < ulength && temp != null && !temp.isEmpty())
{
   temp = data.units[selection][j];
   j++;
}
while(j
第一个调用端口:插入合理的空格,以便代码有一定的可读性…第二个调用端口:为我们提供一段简短但完整的代码。Java、Android或Eclipse中出现问题的可能性非常小。请提供更多代码,n变量来自何处?完整的代码非常长。变量n和selection是整数。n通常递增,而变量selection是从多维数组中获取特定数组的函数参数。我怀疑您的字符串从未实际为null,或者数据为null。由于您试图获取null的第一个字符,units[selection][j][0]将抛出错误。在“temp!=null”,尝试添加“&&!temp.isEmpty()”,同时从temp赋值中删除“[0]”。需要2位数字。如果包含逗号,则会出现numberformatexception。子字符串从索引0开始。它的数学是rightn递增1,对于“01,02,03,04”字符串,它将是子字符串(0,1)子字符串(3,4)子字符串(6,7)子字符串(9,10)该字符串有11个字符。无法将逗号转换为整数。因此子字符串(n*3,n*3+2)表示子字符串(0,2)当n=0时,这将给出所需的3个字符,而不是2个数字,并导致数字格式错误。子字符串返回以第一个索引开头的字符,直到但不包括第二个索引。子字符串(0,1)将给出位置0处的字符,而不是1处的字符。子字符串(0,2)给你位置0和1,但不是2。如果你想返回2个字符进行分析,(0,2)应该给你这个。奇怪,因为它以前不是那样的,但它工作了。将它改为2,这部分现在工作了。谢谢