2016-08-09 8 views
3

私は計算を表示しようとしていますtextView(txtHasil)それは実行中ですが、10個以上のアプリケーションが突然強制終了すると強制終了します。これは私のコードです:アプリケーション入力が10桁以上のときに終了する

btnHitung.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 

     //String plafond = NumberTextWatcherForThousand.trimCommaOfString(edtPlafond.getText().toString()); 
     String plafond = edtPlafond.getText().toString().trim(); 
     String jasa = edtJasa.getText().toString().trim(); 

     int edtPlafond = Integer.parseInt(plafond); 
     float edtJasa = Float.parseFloat(jasa); 

     double hasil = (edtPlafond * edtJasa)/100; 


     txtHasil.setText(""+hasil+"\nplafond: "+edtPlafond+"\nJasa: "+edtJasa); 
     //txtHasil.addTextChangedListener(new NumberTextWatcherForThousand((EditText) txtHasil)); 
    } 
} 

私はtry int、float、およびdoubleを変更しようとしています。私はこのリンクを読んでいる:This program doesn't work properly for decimals more than 10 digits?しかし助けていない。どんな提案も助けになるでしょう。長い...

long edtPlafond; 
try { 

    edtPlafond = Long.parseLong(plafond); 

} catch (NumberFormatException e) { 
    e.printStackTrace(); 
    // add proper error handling 
} 

そして - 感謝

答えて

4
Integer.parseInt(plafond); 

これはproblem.Itは最高の長い値を持っているだろうInteger.MAX_VALUE

int edtPlafond; 
try { 

    edtPlafond = Integer.parseInt(plafond); 

} catch (NumberFormatException e) { 
    e.printStackTrace(); 
    // add proper error handling 
} 

より大きくanythong解析できないですダイアログにエラーを表示することにより、より良い方法でエラーを処理する例:

} catch (NumberFormatException e) { 
     new AlertDialog.Builder(getActivity()) 
      .setTitle("Error: incorrect number entered!") 
      .setMessage("The exact error is: " + e.getMessage()) 
      .setPositiveButton("Ok", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int b) { 
         dialog.cancel(); 
        } 
       }); 
      .create() 
      .show(); 
} 

:すべての変換は、そのような治療を必要とする...

+0

おかげで、それは力の停止よりはましです。しかし、キャッチの少し改正が必要です: 使用({ –

+1

残念ですが、電話から入力していましたが、2つの角かっこの違いを見ていませんでした...また、別のスニペット、より長い値を保持する... – ppeterka

+0

それは冗談を言ったのですか?データ型を理解していない人に、エラー処理を書く方法がわからない人のために...私の心は吹き飛ばされました –

関連する問題