在我的Android应用程序中,我有一个字符串,其值始终为yo_2014_rojo
。 我需要将字符串分为三部分:part1 ="yo"
part2="2014"
和part3="rojo"
。ArrayIndexOutOfBoundsException在拆分字符串
我想如下做到这一点:
String s[] = dato_seleccionado.split("_");
String s1 = s[0];
String s2 = s[1];
String s3 = s[2];
但例外的应用程序崩溃:ArrayIndexOutOfBoundsException
。
任何帮助,欢迎。
你需要把一个断点,似乎'dato_seleccionado'是不是在你的形式期望它崩溃时,否则这将工作得很好。 – 2014-12-02 02:27:25
@Zach如果它为空,OP会得到一个NPE。这绝对不是空的。 – 2014-12-02 02:30:11
@ClaudioRedi,我插入了一个日志来检查dato_seleccionado的值,它现在是12_Diciembre_2014 ...异常说长度= 1,索引= 1 – novato 2014-12-02 02:30:55