android android-widget
Spinner monthSpinner = (Spinner) findViewById(R.id.expMonth);
String selectedmonth=(String)(monthSpinner.getSelectedItem());
int m=Integer.parseInt(selectedmonth.toString());//i am getting error at this statement
System.out.println("Exp-Month"+m);
07-15 11:11:50.568:ERROR / AndroidRuntime(309):java.lang.IllegalStateException:无法执行活动的方法 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.view.View $ 1.onClick(View.java:2072) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.view.View.performClick(View.java:2408) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.view.View $ PerformClick.run(View.java:8816) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.os.Handler.handleCallback(Handler.java:587) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.os.Handler.dispatchMessage(Handler.java:92) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.os.Looper.loop(Looper.java:123) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.app.ActivityThread.main(ActivityThread.java:4627) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at java.lang.reflect.Method.invokeNative(Native Method) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at java.lang.reflect.Method.invoke(Method.java:521) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at dalvik.system.NativeStart.main(Native Method) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):引起:java.lang.reflect.InvocationTargetException 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at com.main.bp.activities.CreditCardActivity.creditCardPayment(CreditCardActivity.java:51) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at java.lang.reflect.Method.invokeNative(Native Method) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at java.lang.reflect.Method.invoke(Method.java:521) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):在android.view.View $ 1.onClick(View.java:2067) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):... 11更多 07-15 11:11:50.568:ERROR / AndroidRuntime(309):引起:java.lang.NumberFormatException:无法将'January'解析为整数 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at java.lang.Integer.parse(Integer.java:433) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at java.lang.Integer.parseInt(Integer.java:422) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):at java.lang.Integer.parseInt(Integer.java:382) 07-15 11:11:50.568:ERROR / AndroidRuntime(309):... 15 more
任何人都可以帮助我将微调器选择的值作为整数
答案 0 :(得分:0)
如果您想要获取所选项目的位置,我认为您应该使用getSelectedItemPosition()
?
(同样在上面的代码中,不需要selectedmonth.toString()
,因为selectedmonth是一个String变量。)