android


Android String.split() and/or StringTokenizer() not working in While loop


This is very odd...
BufferedReader br = new BufferedReader(new InputStreamReader(openFileInput("file")));
String s;
while ((s = br.readLine()) != null) {
String[] sa = s.split("a");
String a = sa[0];
String b = sa[1];
String c = a + "the letter a was here" + b;
// Do something with String c...
}
I get a force close at the line "String b = sa[1];". java.lang.NullPointerException.
My 'String s' in the loop has multiple 'a' characters, that is not the issue.
'String a' is ALWAYS correct.
But 'String b' always throws the exception.
I declare the variables (sa, a, b, c) outside of the loop, no help.
THE ODD THING, StringTokenizer has the SAME EXACT PROBLEM.
It can only read the first token/split...
StringTokenizer st = new StringTokenizer(s, "a");
int x = st.countTokens();
String a = st.nextToken();
String b = st.nextToken();
String c = a + "the letter a was here" + b;
// Do something with String c...
...inside the same While loop.
SAME EXACT PROBLEM! 'String a' is accurate, when the system gets to the 'String b' line, it throws the same exception/error/force close.
I even check the value of 'int x' just to make sure there are multiple tokens, and there are, again this is not the issue.
WHY in this While loop can I only access/read/assign/use the first split/token of my string that I have split/tokenized???
For what ever reason, when having problems with "BufferedReader", I just uninstall the app from the test phone, and run from scratch, and the problem is fixed. Possible the 'file' gets corrupted, I'm not sure. I've run into this problem twice and uninstalling the app and re-running fixed it both times.

Related Links

Wifi Scan results in Hasmap list giving wrong position
How to do an Augmented Reality SDK on our own
Android custom Keyboard - Key icon won't fit into Key
Ngmaterial angularJs not working on phonegap App dev Android
How to reverse viewpager swiping
No automatic update using the Beta test in the Play Store
Broadcast receiver not receiving
GoogleApiClient identifier expected Android Studio error
how to create login,registration,forgotpassword dynamically
OpenGL ES texture coordinates transformations in vertex shader didn't work
Link to .swf and Compile into .apk
Android achievements are reset after one day
TextInputLayout Render error with gradle 2.3.x
Unsure of where to find this error
Custom color drop shadow around View
Error:Execution failed for task ':app:processDebugResources'. com.android.ide.common.process.ProcessException: Failed to execute aapt

Categories

HOME
fabricjs
amp-html
ns-3
twig
spring-data-mongodb
nsbundle
simulink
hugo
jquery-ui
retrofit2
github-enterprise
cmdb
gkturnbasedmatch
symbol
coin3d
mvc-mini-profiler
sencha-touch
boost-icl
selinux
rubymotion
exploit
gmock
froala
surveymonkey
slidetoggle
fable-f#
linked-data
android-things
quantlib
cppreference
dst
mockjax
code-snippets
sammy.js
activexobject
nested-lists
batching
xajax
latitude-longitude
nohup
stringtokenizer
apriori
logback-groovy
x++
openal
jquery-ui-draggable
corruption
carrot2
stdmap
java-6
cubism.js
angular2-testing
dotnetnuke-7
android-dateutils
udpclient
embedding
gcloud-ruby
halcon
crouton-os
libvlc
custom-errors
pypiserver
wiredep
intel-c++
visual-sourcesafe-2005
rdflib
google-refine
teamcity-9.1
rickshaw
imagefilter
xml-dsig
android-framework
vbe
koala
multiautocompletetextview
xmltodict
artemis
kendo-dataviz
away3d
cnf
cmmi
process-explorer
kaleidoscope
diem
chart-director
xcode3.2
veracity
saleslogix
subproject
mapping-by-code
oracle-enterprise-linux
usertype
google-maps-mobile
u2netdk
event-receiver
photolibrary
commerceserver2007
hbm2java
tabpanel
blender-2.49
pagemethods
murmurhash
sifr3
scrubyt
flvplayback
java1.4
business-model
soappy
contentpresenter
pnrp
netbeans6.1

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App