Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.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 Can';在数组中找不到正确的位置_Java_Android_Arrays - Fatal编程技术网

Java Can';在数组中找不到正确的位置

Java Can';在数组中找不到正确的位置,java,android,arrays,Java,Android,Arrays,我的数据库中有一个表,它有一些列,如time和text。。。我希望所有条目都存在于单独字符串数组中的任何列中 我确信两个字符串数组正确地收集了条目(使用toast进行测试!)…我的第一个数组是文本,第二个数组是时间。。。我想根据插入时间找到最后插入的两个文本。。。如果我在时间数组中找到两个最大时间s,使用它们的位置,我可以从文本数组中找到相关文本。。。这是我的密码: double maxtime = 0; double second_maxtime = 0;

我的数据库中有一个表,它有一些列,如
time
text
。。。我希望所有条目都存在于单独字符串数组中的任何列中

我确信两个字符串数组正确地收集了条目(使用toast进行测试!)…我的第一个数组是
文本
,第二个数组是
时间
。。。我想根据插入时间找到最后插入的两个文本。。。如果我在
时间
数组中找到两个最大
时间
s,使用它们的位置,我可以从
文本
数组中找到相关文本。。。这是我的密码:

        double maxtime = 0;
        double second_maxtime = 0;

        for (int counter = 0; counter < i; counter++) {

                if (Double.parseDouble(times[counter]) > maxtime) {
                    second_maxtime = maxtime;
                    maxtime = Double.parseDouble(times[counter]);
                } else if (Double.parseDouble(times[counter]) > second_maxtime &&           Double.parseDouble(times[counter]) != maxtime) {

                    second_maxtime = Double.parseDouble(times[counter]);
                }
         }

        long scndmxt= Math.round(second_maxtime);
        String scndmaxt = String.valueOf(scndmxt);
        int pos = Arrays.asList(times).indexOf(scndmaxt);

        long mxt = Math.round(maxtime);
        String maxt = String.valueOf(mxt);
        int pos1 = Arrays.asList(times).indexOf(maxt);

          String  last_text  = texts[pos];
          String  second_last_text = texts[pos1];
double maxtime=0;
双秒_最大时间=0;
用于(int计数器=0;计数器maxtime){
second_maxtime=maxtime;
maxtime=Double.parseDouble(times[counter]);
}else if(Double.parseDouble(times[counter])>second_maxtime&&Double.parseDouble(times[counter])!=maxtime){
second_maxtime=Double.parseDouble(times[counter]);
}
}
long-scndmxt=Math.round(秒最大时间);
字符串scndmaxt=String.valueOf(scndmxt);
int pos=Arrays.asList(times).indexOf(scndmaxt);
长mxt=数学圆(最大时间);
String maxt=String.valueOf(mxt);
int pos1=Arrays.asList(times).indexOf(maxt);
字符串last_text=文本[pos];
字符串second_last_text=text[pos1];
但是,当我尝试使用toast测试它是否正常工作时,它可以在最后一次正确地找到两个(
mxt
scndmxt
)。。。但是他们的立场不对。。。有时是
-1
0
。。有时是
0
ad
1


我尝试了
intpos=Arrays.asList(otherArray.indexOf(…)对于其他数组,它可以正常工作…但在这里,我应该将字符串转换为double以进行比较。。。有人帮忙吗?!!谢谢…

首先,为什么要使用Double作为时间戳,而应该使用long。 下面的代码可能会对您有所帮助

 long maxtime = 0;
 long second_maxtime = 0;
 int maxPos;
 int secondMaxPos;

        for (int counter = 0; counter < timestampArray.length; counter++) {

                if (Long.parseLong(times[counter]) > maxtime) {
                    second_maxtime = maxtime;
                    maxtime = Long.parseLong(times[counter]);
                    maxPos = counter;
                } else if (Long.parseLong(times[counter]) > second_maxtime &&           Long.parseLong(times[counter]) != maxtime) {

                    second_maxtime = Long.parseLong(times[counter]);
                    secondMaxPos = counter;
                }
         }

String  last_text  = texts[maxPos];
String  second_last_text = texts[secondMaxPos];
long maxtime=0;
长秒_最大时间=0;
int-maxPos;
int-secondMaxPos;
for(int counter=0;计数器maxtime){
second_maxtime=maxtime;
maxtime=Long.parseLong(times[counter]);
maxPos=计数器;
}否则如果(Long.parseLong(times[counter])>second_maxtime&&Long.parseLong(times[counter])!=maxtime){
second_maxtime=Long.parseLong(times[counter]);
secondMaxPos=计数器;
}
}
字符串last_text=文本[maxPos];
字符串second_last_text=文本[secondMaxPos];

for(int counter=0;counterdates.lengh
…我想。。。