我有这个Android电话本应用程序,然后我需要实现添加,编辑,删除和搜索。但是我在搜索方法中获取行的输入文本时遇到错误。
我的logcat中出现了这个错误:
10-15 23:28:12.450: E/AndroidRuntime(407): FATAL EXCEPTION: main
10-15 23:28:12.450: E/AndroidRuntime(407): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.contactslocator/com.example.contactslocator.Search}: java.lang.NumberFormatException:
10-15 23:28:12.450: E/AndroidRuntime(407): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.os.Handler.dispatchMessage(Handler.java:99)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.os.Looper.loop(Looper.java:123)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-15 23:28:12.450: E/AndroidRuntime(407): at java.lang.reflect.Method.invokeNative(Native Method)
10-15 23:28:12.450: E/AndroidRuntime(407): at java.lang.reflect.Method.invoke(Method.java:521)
10-15 23:28:12.450: E/AndroidRuntime(407): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-15 23:28:12.450: E/AndroidRuntime(407): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-15 23:28:12.450: E/AndroidRuntime(407): at dalvik.system.NativeStart.main(Native Method)
10-15 23:28:12.450: E/AndroidRuntime(407): Caused by: java.lang.NumberFormatException:
10-15 23:28:12.450: E/AndroidRuntime(407): at java.lang.Long.parseLong(Long.java:347)
10-15 23:28:12.450: E/AndroidRuntime(407): at java.lang.Long.parseLong(Long.java:320)
10-15 23:28:12.450: E/AndroidRuntime(407): at com.example.contactslocator.Search.onCreate(Search.java:29)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-15 23:28:12.450: E/AndroidRuntime(407): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-15 23:28:12.450: E/AndroidRuntime(407): ... 11 more
第29行是:
long l = Integer.parseInt(s);
我的代码段是:
String s = sqlRow.getText().toString();
long l = Integer.parseLong(s);
Save ss = new Save (this);
ss.open();
String returnedName = ss.getName(l);
String returnedAddress = ss.getAddress(l);
String returnedNumber = ss.getNumber(l);
String returnedZipcode = ss.getZipcode(l);
String returnedCategory = ss.getCategory(l);
ss.close();
sqlName.setText(returnedName);
sqlAddress.setText(returnedAddress);
sqlMobilenum.setText(returnedNumber);
sqlZipcode.setText(returnedZipcode);
sqlCategory.setText(returnedCategory);
我尝试将long更改为int,但我仍然遇到错误can't parse ''
为什么我在第29行遇到此错误?