嗨,我正在尝试将诸如“abc-d1_23QWEwer”之类的字符串转换为整数
StringBuilder sb = new StringBuilder();
int intServiceName = 0;
String stringServiceValue;
for (int i = 0; i < serviceName.length(); i++){
if (DEBUG) Log.i(TAG, "serviceName.length() loop i: " + i);
sb.append(String.valueOf(Character.getNumericValue(serviceName.charAt(i))));
if (DEBUG) Log.i(TAG, "serviceName.length() loop i after: " + i);
}
if (DEBUG) Log.i(TAG, "serviceName.length() loop end2");
stringServiceValue = sb.toString();
if (DEBUG) Log.i(TAG, "serviceName.length() loop end: "+stringServiceValue.replaceAll("\\D+",""));
stringServiceValue = stringServiceValue.replaceAll("\\D+","");
if (DEBUG) Log.i(TAG, "serviceName.length() loop endstringServiceValue: "+ stringServiceValue);
intServiceName = Integer.parseInt(stringServiceValue);
if (DEBUG) Log.i(TAG, "serviceName.length() loop end123123: "+ String.valueOf(intServiceName));
当代码到达这一行时,我收到一个错误:
intServiceName = Integer.parseInt(stringServiceValue);
我究竟做错了什么?这是错误日志
06-21 19:12:54.760: E/AndroidRuntime(11139): FATAL EXCEPTION: AsyncTask #4
06-21 19:12:54.760: E/AndroidRuntime(11139): java.lang.RuntimeException: An error occured while executing doInBackground()
06-21 19:12:54.760: E/AndroidRuntime(11139): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-21 19:12:54.760: E/AndroidRuntime(11139): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.lang.Thread.run(Thread.java:856)
06-21 19:12:54.760: E/AndroidRuntime(11139): Caused by: java.lang.NumberFormatException: Invalid int: "2914282912918292114"
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.lang.Integer.invalidInt(Integer.java:138)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.lang.Integer.parse(Integer.java:378)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.lang.Integer.parseInt(Integer.java:366)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.lang.Integer.parseInt(Integer.java:332)
06-21 19:12:54.760: E/AndroidRuntime(11139): at com.wr.noc.AsyncTasks.doInBackground(AsyncTasks.java:113)
06-21 19:12:54.760: E/AndroidRuntime(11139): at com.wr.noc.AsyncTasks.doInBackground(AsyncTasks.java:1)
06-21 19:12:54.760: E/AndroidRuntime(11139): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-21 19:12:54.760: E/AndroidRuntime(11139): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-21 19:12:54.760: E/AndroidRuntime(11139): ... 5 more