-2

I am making a basic application for my electronics lab to calculate microstrip parameters.

Consists of many activities. But this is the one where I keep on getting errors.

There are a lot of files hence I am putting a Github link in the bottom. I will include the code which led to the error.

package com.example.microstripcalculator;

import android.content.Intent;
        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.view.View;

public class LossIntermediateCalc extends AppCompatActivity {
    Double o,s,z,w,rs,alphac,u;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loss_intermediate_calc);



        Intent values = getIntent();
        o = Double.valueOf(values.getExtras().getString("om"));
        s=  Double.valueOf(values.getExtras().getString("si"));
        z = Double.valueOf(values.getExtras().getString("zc"));
        w = Double.valueOf(values.getExtras().getString("wi"));

        u =  0.00000125663706;
        rs = Math.sqrt(o*u/(2*s));
        alphac = (8.686*rs)/(z*w);
    }


    public void losses_final(View view){
        Intent loss_final = new Intent(this,LossesFinal.class);
        loss_final.putExtra("alpha",alphac);

        startActivity(loss_final);
    }


}

Here is the logcat file.

04-16 10:35:56.941 851-851/com.example.microstripcalculator E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.microstripcalculator, PID: 851
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.microstripcalculator/com.example.microstripcalculator.LossIntermediateCalc}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6809)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
        at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
        at java.lang.Double.parseDouble(Double.java:539)
        at java.lang.Double.valueOf(Double.java:503)
        at com.example.microstripcalculator.LossIntermediateCalc.onCreate(LossIntermediateCalc.java:21)
        at android.app.Activity.performCreate(Activity.java:6998)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1230)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2899)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3046) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6809) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
04-16 10:35:56.942 851-851/com.example.microstripcalculator D/AppTracker: App Event: crash

Here is the github file if you need something else. Github

I am new to android and will be grateful if you guys help me out. Thanks in advance.

code_crusher
  • 53
  • 2
  • 8

1 Answers1

0
   Retrieve like this:
    Intent i = getIntent();
    String om = i.getStringExtra("om");

then parse to double

dev
  • 260
  • 2
  • 12