誰も私のJavaプログラムで私を助けることができますか?私は現在通貨変換を行っています。ユーザーは英ポンド金額を入力して変換するために変換をクリックし、変換に独自の為替レートを入力するオプションを持っています。それは私が設定したものの代わりにユーザーが入力した為替レートを使用します。ここで私はこれまでにGBPをUSDに変換するコードを持っていますが、プログラムは金額を入力して自分で為替レートを入力するときに機能しますが、入力換算レートボックスを空にして一定の為替レートを使用するオプションは変換エラー:(何もこのボックスに入力されていない場合に二重GBPtoUSDを使用しなければならない)の為替レートを入力することなく、変換Java Netbeans IDE、私にエラーを与える変換
public class cConverter extends javax.swing.JFrame {
double GBPtoUSD = 1.288;
//this is the constant exchange rate for GBP to USD.
private void BtnConvertActionPerformed(java.awt.event.ActionEvent evt) {
double ConvertFromGBP = Double.parseDouble(InputFrom.getText());
double GetExchange = Double.parseDouble(ExchangeRateFrom.getText());
/* Input from is where the user inputs the GBP amount they want converted.
ExchangeRateFrom is the optional exchange rate box where the user inputs an
updated exchange rate if the constant one is out of date. */
if (CurrencyTop.getSelectedItem().equals("USD")){
String cGBPtoUSD = String.format("%.2f", ConvertFromGBP * GBPtoUSD);
ConvertedFrom.setText(cGBPtoUSD);
}
else if (CurrencyTop.getSelectedItem().equals("USD")) {
String uGBPtoUSD = String.format("%.2f", GetExchange * ConvertFromGBP);
ConvertedFrom.setText(uGBPtoUSD);
}
/* CurrencyTop is a combo box containing the currencies to convert to.
ConvertedFrom is the calculation output label. */
エラー例外:スレッドで
例外「AWT-EventQueueの-0」 java.lang.NumberFormatException:空文字列
返信いただきありがとうございますxormar、私はあなたが私に与えたコードを実装しましたが、私はまだ同じエラーが発生しています。 –
InputFrom.getText()で空の入力をチェックしましたか? ExchangeRateFromでは何が起こっていますか?完全なスタックトレースと更新されたコードを投稿に追加できますか?たぶん、どこか他の場所でエラーが起こるでしょうか? – xormar
https://gist.github.com/liamrice18/2aae2ec72bdfa34ea308519d131c47b8 –