0

I can not figure out why this code output always show NaN. Is there anybody who can help me figure out where I did mistake?

package com.example.user.solar_calculator;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.content.Context;
import android.content.Intent;

import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

public class efficiency extends Activity {
    Button button;
    EditText efficiency;
    EditText vol;

    String e,v;

    double e1,wat,v1, AC_Load_in_ampere_hour_calculation,dc;
    double load,load_vol,Total_Daily_load,lol;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_efficiency);
        initControls();
        addListenerOnButton();
    }

    public void initControls() {
        efficiency=(EditText)findViewById(R.id.editText1);
        vol=(EditText)findViewById(R.id.editText2);
        button=(Button)findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    e1=Double.parseDouble(efficiency.getText().toString()); // Make use of autoboxing.  It's also easier to read.
                } catch (NumberFormatException e) {
                    e1=1;
                }
                try {
                    v1=Double.parseDouble(vol.getText().toString());// Make use of autoboxing.  It's also easier to read.
                } catch (NumberFormatException e) {
                    v1=1;
                }

                Bundle extras = getIntent().getExtras();
                if(extras !=null) {
                    String value = extras.getString("FOUR");
                    load=Double.parseDouble(value.toString());
                }
                wat=load_vol*(1+.1);

                AC_Load_in_ampere_hour_calculation = (load)/( v1* (e1/100));

                Total_Daily_load=AC_Load_in_ampere_hour_calculation+dc;

                Intent i = new Intent(efficiency.this, calculation.class);
                //Create the bundle
                Bundle bundle = new Bundle();
                //Add your data to bundle

                bundle.putString("seven", String.valueOf(AC_Load_in_ampere_hour_calculation));
                bundle.putString("eight", String.valueOf(Total_Daily_load));
                bundle.putString("nine", String.valueOf(dc));

                //Add the bundle to the intent
                i.putExtras(bundle);
                //Fire that second activity
                startActivity(i);
            }
        });
    }

    public void addListenerOnButton() {    
        final Context context = this;    
        button = (Button) findViewById(R.id.button);    
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
Joshua
  • 5,901
  • 2
  • 32
  • 52
orvi
  • 3,142
  • 1
  • 23
  • 36

1 Answers1

2

I think the line who cause problem is AC_Load_in_ampere_hour_calculation = (load)/( v1* (e1/100));

Because if v1 = 0 it will be impossible.

Greenkiller
  • 200
  • 2
  • 12