String Tokenizing from file in android -


i have file stored in phone "savett.txt" . every word in file seperated spaces. wish retrieve each word file , display every word in seperate textviews. how this. please help

i able retrieve contents of file string following code

try {             bufferedreader inputreader = new bufferedreader(new inputstreamreader(                     openfileinput("savett.txt")));              stringbuffer stringbuffer = new stringbuffer();                             while ((inputstring = inputreader.readline()) != null) {                 stringbuffer.append(inputstring + "\n");                 //edittext txt = (edittext) findviewbyid(r.id.temp);                 //txt.settext(inputstring);             }             } catch (ioexception e) {             e.printstacktrace();         } 

with code entire string inputstring after . tokenizing string following code

 stringtokenizer tokenizer = new stringtokenizer(inputstring);        string[] arr = new string[tokenizer.counttokens()];        while(tokenizer.hasmoreelements())        {           arr[i]= tokenizer.nexttoken();           i++;        } 

with above code trying save eack token in array. next try display text in textviews.

i dont know goig wrong. activity stopped , nullpointer exception displayed.

i figured out problem myself. problem value of inputstring inaccessible outside try catch block since set inside block;

so if write string tokenisation block inside try catch works fine


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -