我正在为我的电子实验室制作一个计算微带参数的基本应用程序。
包含许多活动。但这是我继续犯错误的地方。
有很多文件,因此我在底部放置了一个Github链接。 我将包含导致错误的代码。
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);
}
}
这是logcat文件。
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
如果你需要别的东西,这是github文件。 Github
我是Android的新手,如果你们帮助我,我将不胜感激。提前谢谢。
答案 0 :(得分:0)
Retrieve like this:
Intent i = getIntent();
String om = i.getStringExtra("om");
然后解析为双重