project advanced calculation, android error: "java.lang.NullPointerException at java.lang.StringToReal.parseFloat (StringToReal.java:285)"

1

I am creating a project in android studio, in the first instance the app asks the user what kind of calculation he wants to do, after that he asks that he provide a certain amount of data, because there were many divided into three activities including one for the results As the data collected from each should go to the last window to be solved (fourth activity if it is counted from the main), try to try it, in the first case there were no problems, but when I go through the third activity, it tells me that the application had an error, I can not see where this idea is.

    switch (view.getId()) {
        case R.id.siguiente_electrica:


             Intent info =new Intent(SegundaActivity.this, resultados_electricos.class);
             Editable D= d.getText();
             String NCF= ncf.getText().toString();
             String A= disa.getText().toString();
             String B= disb.getText().toString();
             String C= disc.getText().toString();


            info.putExtra("fases", NCF);
            info.putExtra("diametro", D);
            info.putExtra("a",A);
            info.putExtra("b",B);
            info.putExtra("c",C);

            startActivity(info);

            Intent siguiente = new Intent(SegundaActivity.this, e_electrica2Activity.class);
            startActivity(siguiente);
            break;

third activity

    switch (view.getId()){
        case R.id.siguiente2_electrica:

            Intent info2= new Intent(e_electrica2Activity.this,resultados_electricos.class);
            String RO=ro.getText().toString();
            String NHILOS= nh.getText().toString();
            String TEMP1= t1.getText().toString();
            String TEMP2= t2.getText().toString();
            String LONGLINE= longl.getText().toString();


            info2.putExtra("nhilos",NHILOS);
            info2.putExtra("temp1",TEMP1);
            info2.putExtra("temp2",TEMP2);
            info2.putExtra("LongLine",LONGLINE);
            info2.putExtra("ro",RO);

            startActivity(info2);

            Intent siguiente_2= new Intent(e_electrica2Activity.this,resultados_electricos.class);
            startActivity(siguiente_2);

            break;

Activity that receives the data: 'Button Calculate;     int ncf;     float d, a, b, c, ro, nhilos, temp1, temp2, LongLine;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_resultados_electricas);
    Calcular = (Button) findViewById(R.id.calcular);
    Calcular.setOnClickListener(this);
    String aux_d = getIntent().getStringExtra("diametro");
    String aux_ncf = getIntent().getStringExtra("fases");
    String aux_a = getIntent().getStringExtra("a");
    String aux_b = getIntent().getStringExtra("b");
    String aux_c = getIntent().getStringExtra("c");
    String aux_ro = getIntent().getStringExtra("ro");
    String aux_nhilos = getIntent().getStringExtra("nhilos");
    String aux_temp1 = getIntent().getStringExtra("temp1");
    String aux_temp2 = getIntent().getStringExtra("temp2");
    String aux_LongLine = getIntent().getStringExtra("Longline");

// to convert variables to numbers //         d = Float.parseFloat (aux_d);         ncf = Integer.parseInt (aux_ncf);         a = Float.parseFloat (aux_a);         b = Float.parseFloat (aux_b);         c = Float.parseFloat (aux_c);         ro = Float.parseFloat (aux_ro);         nhilos = Float.parseFloat (aux_nhilos);         temp1 = Float.parseFloat (aux_temp1);         temp2 = Float.parseFloat (aux_temp2);         LongLine = Float.parseFloat (aux_LongLine);

}

@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.calcular:
            if (ncf == 1) {
                double rmg = (d / 2.0);
                double dmg = Math.pow(a * b * c, 1.0 / 3.0);
                double area = (Math.PI) * (Math.pow(rmg, 2.0));
                double resist = (ro * 1000) / area;
                double resisttemp = ((228 + temp2) / (228 + temp1)) * resist;
                double resisline = resisttemp * LongLine;
                double inductancia = ((1 / 2 * ncf) + (4.6 * (dmg / rmg))) * 0.0001;
                double reacinduc = inductancia * (Math.PI) * 120;
                double reacinducline = reacinduc * LongLine;
                double capac = (24.2 * 1E-9) / (Math.log(dmg / rmg));
                double reaccap = capac * 120 * (Math.PI);
                double reaccapline = reaccap * LongLine;
            }

            break;[![introducir la descripción de la imagen aquí][1]][1]'

I appreciate any help.

The error that occurs in logcat FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.abraham.myapplication/com.example.abraham.myapplication.resultados_electricasActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) at android.app.ActivityThread.access$600(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at java.lang.StringToReal.parseFloat(StringToReal.java:285) at java.lang.Float.parseFloat(Float.java:300) at com.example.abraham.myapplication.resultados_electricasActivity.onCreate(resultados_electricasActivity.java:31) at android.app.Activity.performCreate(Activity.java:5008) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)  at android.app.ActivityThread.access$600(ActivityThread.java:130)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:137)  at android.app.ActivityThread.main(ActivityThread.java:4745)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:511)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)  at dalvik.system.NativeStart.main(Native Method) 

    
asked by Abraham silva millan 23.01.2018 в 06:21
source

2 answers

1

When using putExtra, you are sending one or more attributes between activities, when receiving the attribute in the destination activity, make sure that you are obtaining them with the id that you assigned in the previous activity.

Examples:

Activity 1:

i.putExtra("miID", strName);

answered by 23.01.2018 / 14:08
source
0

The problem is specified:

Caused by: java.lang.NullPointerException                                                                                 at java.lang.StringToReal.parseFloat(StringToReal.java:285)
at java.lang.Float.parseFloat(Float.java:300)
at com.example.abraham.myapplication.resultados_electricasActivity.onCreate(resultados_electricasActivity.java:31)

This problem is generated when you try to convert a null value to Float:

Float.parseFloat(null) 

You must ensure to send the data in the Intent, in this block of code you can see the problem:

  switch (view.getId()){
        case R.id.siguiente2_electrica:

            Intent info2= new Intent(e_electrica2Activity.this,resultados_electricos.class);
            String RO=ro.getText().toString();
            String NHILOS= nh.getText().toString();
            String TEMP1= t1.getText().toString();
            String TEMP2= t2.getText().toString();
            String LONGLINE= longl.getText().toString();


            info2.putExtra("nhilos",NHILOS);
            info2.putExtra("temp1",TEMP1);
            info2.putExtra("temp2",TEMP2);
            info2.putExtra("LongLine",LONGLINE);
            info2.putExtra("ro",RO);

            startActivity(info2);

            Intent siguiente_2= new Intent(e_electrica2Activity.this,resultados_electricos.class);
            startActivity(siguiente_2); //* No se estan enviando valores en este Intent.

            break;

When you perform the intent to open the results, you are not adding the values:

       Intent siguiente_2= new Intent(e_electrica2Activity.this,resultados_electricos.class);
        startActivity(siguiente_2); 

for that reason when you try to get them they have null value.

    
answered by 23.01.2018 в 20:42