我需要从包含正值和负值的文件(.csv)中读取值。在将字符串转换为整数时出现错误。
Scanner sc = new Scanner(getAssets().open("Book1.csv")).useDelimiter(",");
int i = 0;
while (sc.hasNext()) {
String str = sc.next();
data[i] = new GraphViewData(i, Integer.parseInt(str));
i++;
}
下面是我的日志:
05-02 04:05:55.119: E/AndroidRuntime(3003): ' as integer
05-02 04:05:55.119: E/AndroidRuntime(3003): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-02 04:05:55.119: E/AndroidRuntime(3003): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-02 04:05:55.119: E/AndroidRuntime(3003): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-02 04:05:55.119: E/AndroidRuntime(3003): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-02 04:05:55.119: E/AndroidRuntime(3003): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 04:05:55.119: E/AndroidRuntime(3003): at android.os.Looper.loop(Looper.java:123)
05-02 04:05:55.119: E/AndroidRuntime(3003): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-02 04:05:55.119: E/AndroidRuntime(3003): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 04:05:55.119: E/AndroidRuntime(3003): at java.lang.reflect.Method.invoke(Method.java:507)
05-02 04:05:55.119: E/AndroidRuntime(3003): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-02 04:05:55.119: E/AndroidRuntime(3003): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-02 04:05:55.119: E/AndroidRuntime(3003): at dalvik.system.NativeStart.main(Native Method)
05-02 04:05:55.119: E/AndroidRuntime(3003): Caused by: java.lang.NumberFormatException: unable to parse '893