Java Seekbar因字符串格式而崩溃
当我在format方法中输入%0.02f作为参数时,我的tip calculator应用程序上的SeekBar崩溃Java Seekbar因字符串格式而崩溃,java,android,seekbar,changelistener,Java,Android,Seekbar,Changelistener,当我在format方法中输入%0.02f作为参数时,我的tip calculator应用程序上的SeekBar崩溃 tipAmountEditText.setText(String.format("%0.02f", tipAmount)); 我解决了这个问题,删除了整数部分,因此变成了%.02f。关于这个问题,我能说的唯一一个特性是它是使用ChangeListener弹出的。我不明白为什么这会是一个问题,我希望有人能启发我。如果您需要了解更大的情况,我的代码全部都在我的github上: 这里是
tipAmountEditText.setText(String.format("%0.02f", tipAmount));
我解决了这个问题,删除了整数部分,因此变成了%.02f
。关于这个问题,我能说的唯一一个特性是它是使用ChangeListener弹出的。我不明白为什么这会是一个问题,我希望有人能启发我。如果您需要了解更大的情况,我的代码全部都在我的github上:
这里是String.format(“%0.02f”,tipAmount)
您将获得
java.util.MissingFormatWidthException
//This Unchecked exception thrown when the format width is required.
原因:
因此,请使用下面的方法
我可以知道
#
的目的吗?另外,零是如何导致崩溃的?这是参数格式问题吗?
java.util.MissingFormatWidthException
//This Unchecked exception thrown when the format width is required.
%0.02f interprets as a floating point at least 0 wide.
Thats why it gives MissingFormatWidthException // as its assuming width to 0
String.format("%.02f", tipAmount)