【发布时间】:2013-08-07 13:35:50
【问题描述】:
// Get the text file
File file = new File(Environment.getExternalStorageDirectory()
+ "/Config/GPSListenerminTime.cfg");
// Read text from 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 to add proper error handling here
}
我想使用此代码从文件中读取一个数字,它运行良好,但我如何在 requestLocationUpdates 中将该数字用作长值? 我尝试以这种方式使用它,但它不起作用:
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, Long.valueOf(String.valueOf(GPSListenerminTime)), 0, this);
我的文件只包含这个数字:10000 启动服务时出现此错误:
08-07 15:32:45.599: E/AndroidRuntime(19878): java.lang.RuntimeException:
Unable to create service com.example.gpslog.DataLogService: java.lang.NumberFormatException: 10000
【问题讨论】: