java - Android: fill spinner with items in text file -


i want fill spinner items in text file on hosting. text file content separate "\n" character:

afghanistan albania algeria andorra angola 

i write code i've error :

03-10 12:32:07.716: e/androidruntime(7670):  fatal exception: thread-69056 03-10 12:32:07.716:   e/androidruntime(7670):  java.lang.arrayindexoutofboundsexception:  length=91; index=91                      bo.write(buffer);                     string s = bo.tostring();                      final vector<string> str = new vector<string>();                     string[] line = s.split("\n");                     int index = 0;                     while (line[index] != null) {                         str.add(line[index]);                         index++;                     } 

you need change condition.. this:

while (line[index] != null) {    str.add(line[index]);    index++; } 

if size of line 10, index++ make 11. line[11] not null rather throw arrayindexoutofboundsexception.

change condition :

for(int i=0;i<line.length;i++) {     if(line[i] != null) {        str.add(line[index]);     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -