android - How can i turn Stringbuilder variable to a long? -
// text file file file = new file(environment.getexternalstoragedirectory() + "/config/gpslistenermintime.cfg"); // read text file stringbuilder gpslistenermintime = new stringbuilder(); try { bufferedreader br = new bufferedreader(new filereader(file)); string line; while ((line = br.readline()) != null) { gpslistenermintime.append(line); gpslistenermintime.append('\n'); } } catch (ioexception e) { // todo you'll need add proper error handling here }
i want read number file code , works well, how can use number long value in requestlocationupdates? tried use way not working:
lm = (locationmanager) getsystemservice(context.location_service); lm.requestlocationupdates(locationmanager.gps_provider, long.valueof(string.valueof(gpslistenermintime)), 0, this);
my file contains number: 10000 error when staring service:
08-07 15:32:45.599: e/androidruntime(19878): java.lang.runtimeexception: unable create service com.example.gpslog.datalogservice: java.lang.numberformatexception: 10000
numberformatexception result of parsing "1000/n" string. remove empty characters trim() method :
long.valueof(yourstringbuilder.tostring().trim());
Comments
Post a Comment