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

When using an AutoCompleteTextView, can I run code between user clicking and populating the textbox with the answer?
Proguard dontwarn and dontnote not taking effect
Is there a way to move Component Tree back to right?
Handling event by data binding vs onClick assigned to a method in an Activity
Implement onMarkerPositionReached for new API in MusicService
Why doesn't the MidiInputPort.flush() clear the buffer in Android?
Change ToolBar Title color through app style
onLoadFinished() not getting called when activity is in onstop state
how to use like operation in sqlite android
Can i use firebase cloud messaging to create an android chat application to be used at large scale [closed]
As I can move a marker in a MapFragment in real time? [closed]
Unity3d ARTookit5 Blurred camera on android mobile
Android Multi Screen , drag and drop not working with WebView
Why can't my haxe / openfl app install and launch on the android emulator
Ionic Push Notification: Not receiving in IOS
My AVD not working for some reason

Categories

HOME
windows
asp.net-web-api
scikit-learn
cobalt
gdb
camera
r-googlesheets
polling
jquery-ui
spring-session
title
elasticsearch-5
accessibility
endeca
activecollab
stellar.js
favicon
scrolltop
heat
do-while
intershop
mathprog
vuejs
nim
nodemcu
backpack-for-laravel
froala
motion-detection
nstimer
intersystems-cache
sqsh
testcomplete
hibernate-validator
clickjacking
twos-complement
android-maps-extensions
keras-layer
connection-pool
bc
news
ogc
portforwarding
x++
pom.xml
getchar
jboss-4.2.x
wcftestclient
insight
payara-micro
colorbar
sundials
pdf-conversion
oozie-coordinator
google-photos
bootstrap-tags-input
microstation
file-uri
signalr.client
drawstring
hadoop-partitioning
phpwebsocket
toast
jbase
include-guards
visual-sourcesafe-2005
sony-lifelog-api
uncompress
execve
filesplitting
webfinger
imagefilter
radiant
websphere-esb
sbcl
android-usb
facebook-timeline
video-codecs
robotlegs
monotouch.dialog
isa-swizzling
pinch
procedures
matlab-load
mysql-error-1205
non-clustered-index
django-piston
wcf-instancing
windows-identity
movieplayer
image-capture
cardspace

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