因此,当我模拟 Android 2.3.3 时,一切正常并显示格式化的值。但是,当我发送到我的手机时它崩溃并且应用程序关闭。当我删除格式化的双重数据时,它在我的手机上工作。
会是什么?
谢谢!
这是代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.editProductValue = (EditText)findViewById(R.id.productValue);
this.editProductShipping = (EditText)findViewById(R.id.productShipping);
this.cbCCFlagNames = (Spinner)findViewById(R.id.cbCCFlag);
this.cbCCInstallments = (Spinner)findViewById(R.id.cbInstallment);
this.btnCalc = (Button)findViewById(R.id.btnCalc);
this.cbCCFlagNames.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
cbCCInstallments.setSelection(Adapter.NO_SELECTION);
String ccName = parent.getItemAtPosition(pos).toString();
Vector<String> lstInstallments = new Vector<String>();
if(ccName.matches("America Express")) {
for(int count = 1; count <= 15; count ++) {
if(count == 1 || count % 3 == 0) {
lstInstallments.add(Integer.toString(count));
}
}
} else if(ccName.matches("Cartão Mercado Livre")) {
for(int count = 1; count <= 24; count ++) {
if(count == 1 || count % 3 == 0 && count != 21) {
lstInstallments.add(Integer.toString(count));
}
}
} else {
for(int count = 1; count <= 12; count ++) {
if(count == 1 || count % 3 == 0) {
lstInstallments.add(Integer.toString(count));
}
}
}
String[] strList = lstInstallments.toArray(new String[lstInstallments.size()]);
ArrayAdapter<String> newList = new ArrayAdapter<String>(Main.this, android.R.layout.simple_list_item_1, strList);
cbCCInstallments.setAdapter(newList);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
return;
}
});
this.btnCalc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if(editProductValue.getText().toString().matches("") || editProductShipping.getText().toString().matches("")) {
Toast.makeText(Main.this, "Por favor, preencha todos os campos!",Toast.LENGTH_LONG).show();
} else {
double value = Double.parseDouble(editProductValue.getText().toString());
double shipp = Double.parseDouble(editProductShipping.getText().toString());
int parcel = Integer.parseInt(cbCCInstallments.getSelectedItem().toString());
DecimalFormat twoDForm = new DecimalFormat("#.##");
double total = 0;
switch(parcel) {
case 1:
total = (value + shipp + ((value + shipp) * 0)) / parcel;
break;
case 3:
total = (value + shipp + ((value + shipp) * 0.0699)) / parcel;
break;
case 6:
total = (value + shipp + ((value + shipp) * 0.1199)) / parcel;
break;
case 9:
total = (value + shipp + ((value + shipp) * 0.1449)) / parcel;
break;
case 12:
total = (value + shipp + ((value + shipp) * 0.1599)) / parcel;
break;
case 15:
total = (value + shipp + ((value + shipp) * 0.1849)) / parcel;
break;
case 18:
total = (value + shipp + ((value + shipp) * 0.2149)) / parcel;
break;
case 24:
total = (value + shipp + ((value + shipp) * 0.2799)) / parcel;
break;
}
total = Double.valueOf(twoDForm.format(total));
double totalParcel = Double.valueOf(twoDForm.format(total * parcel));
String message = "Parcelas: " + parcel
+ "x\nValor das Parcelas: R$" + total
+ "\nTotal a Prazo: R$" + totalParcel
+ "\n\nOBS.: As taxas de juros estão sujeitas a mudanças de acordo com o Mercado Livre.";
AlertDialog.Builder result = new AlertDialog.Builder(Main.this);
result.setTitle("Total Parcelado");
result.setMessage(message);
result.setNeutralButton("Fechar", null);
result.show();
}
}
});
这是日志猫
05-15 16:54:14.439: E/AndroidRuntime(28844): FATAL EXCEPTION: main
05-15 16:54:14.439: E/AndroidRuntime(28844): java.lang.NumberFormatException
05-15 16:54:14.439: E/AndroidRuntime(28844): at org.apache.harmony.luni.util.FloatingPointParser.parseDblImpl(Native Method)
05-15 16:54:14.439: E/AndroidRuntime(28844): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:283)
05-15 16:54:14.439: E/AndroidRuntime(28844): at java.lang.Double.parseDouble(Double.java:318)
05-15 16:54:14.439: E/AndroidRuntime(28844): at java.lang.Double.valueOf(Double.java:356)
05-15 16:54:14.439: E/AndroidRuntime(28844): at br.com.grindsoft.calcjurml.Main$2.onClick(Main.java:127)
05-15 16:54:14.439: E/AndroidRuntime(28844): at android.view.View.performClick(View.java:2485)
05-15 16:54:14.439: E/AndroidRuntime(28844): at android.view.View$PerformClick.run(View.java:9080)
05-15 16:54:14.439: E/AndroidRuntime(28844): at android.os.Handler.handleCallback(Handler.java:587)
05-15 16:54:14.439: E/AndroidRuntime(28844): at android.os.Handler.dispatchMessage(Handler.java:92)
05-15 16:54:14.439: E/AndroidRuntime(28844): at android.os.Looper.loop(Looper.java:123)
05-15 16:54:14.439: E/AndroidRuntime(28844): at android.app.ActivityThread.main(ActivityThread.java:3729)
05-15 16:54:14.439: E/AndroidRuntime(28844): at java.lang.reflect.Method.invokeNative(Native Method)
05-15 16:54:14.439: E/AndroidRuntime(28844): at java.lang.reflect.Method.invoke(Method.java:507)
05-15 16:54:14.439: E/AndroidRuntime(28844): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
05-15 16:54:14.439: E/AndroidRuntime(28844): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
05-15 16:54:14.439: E/AndroidRuntime(28844): at dalvik.system.NativeStart.main(Native Method)