我的应用程序崩溃,我不知道为什么

时间:2018-06-13 13:50:32

标签: java android

所以我试图制作一个单位转换应用程序,在我成功将所有单位转换为用户输入后,我试图重复该过程,但我的应用程序崩溃。谁能向我解释我哪里错了?

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this);
        mAdview = (AdView)findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
        mAdview.loadAd(adRequest);
        AdView adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
        km = findViewById(R.id.unit_km);
        mi = findViewById(R.id.unit_mile);
        m  = findViewById(R.id.unit_meters);
        ft = findViewById(R.id.unit_feet);
        yd = findViewById(R.id.unit_yard);
        cm = findViewById(R.id.unit_centimetri);
        in = findViewById(R.id.unit_inch);
        conv = findViewById(R.id.convert);
        clear = findViewById(R.id.clear);

        conv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try{
                double value_km = Double.valueOf(km.getText().toString());
                km.setText(Double.valueOf(value_km).toString()+ " Kilometers");
                mi.setText(Double.valueOf(UnitConverter.kilometri2Mile(value_km)).toString()+" Mile");
                m.setText(Double.valueOf(UnitConverter.kilometri2Metri(value_km)).toString()+" Metri");
                ft.setText(Double.valueOf(UnitConverter.kilometri2Feet(value_km)).toString()+" Feet");
                yd.setText(Double.valueOf(UnitConverter.kilometri2Yard(value_km)).toString()+" Yarzi");
                cm.setText(Double.valueOf(UnitConverter.kilometri2Centimetri(value_km)).toString()+" Centimetri");
                in.setText(Double.valueOf(UnitConverter.kilometri2Inch(value_km)).toString()+" Inch");

                double value_mi = Double.valueOf(mi.getText().toString());
                km.setText(Double.valueOf(UnitConverter.mile2Kilometri(value_mi)).toString()+ " Kilometers");
                mi.setText(Double.valueOf(value_mi).toString()+" Mile");
                m.setText(Double.valueOf(UnitConverter.mile2Metri(value_mi)).toString()+" Metri");
                ft.setText(Double.valueOf(UnitConverter.mile2Feet(value_mi)).toString()+" Feet");
                yd.setText(Double.valueOf(UnitConverter.mile2Yarzi(value_mi)).toString()+" Yarzi");
                cm.setText(Double.valueOf(UnitConverter.mile2Centimetri(value_mi)).toString()+" Centimetri");
                in.setText(Double.valueOf(UnitConverter.mile2Inch(value_mi)).toString()+" Inch");
            }catch (Exception e){
                }
            }
        });

0 个答案:

没有答案