我正在为我的应用程序进行更新,我刚刚添加了另一个 tabhost,但我不断收到错误。第一个 tabhost 活动扩展了 TabActivity。我试图用第二个来做到这一点,但它没有用,所以我回到扩展活动。然后我开始遇到其他错误。我正在查看 logcat,其中一个错误是指我的第一个 tabhost 活动,所以我对此有点困惑。我不知道该怎么做。
继承人logcat
06-04 15:50:52.814: E/AndroidRuntime(23237): FATAL EXCEPTION: main
06-04 15:50:52.814: E/AndroidRuntime(23237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.TBJsoft.enclosurecalculator/tbjsoft.enclosurecalculator.DiagramTabHost}: java.lang.NullPointerException
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.os.Looper.loop(Looper.java:137)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-04 15:50:52.814: E/AndroidRuntime(23237): at java.lang.reflect.Method.invokeNative(Native Method)
06-04 15:50:52.814: E/AndroidRuntime(23237): at java.lang.reflect.Method.invoke(Method.java:511)
06-04 15:50:52.814: E/AndroidRuntime(23237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-04 15:50:52.814: E/AndroidRuntime(23237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-04 15:50:52.814: E/AndroidRuntime(23237): at dalvik.system.NativeStart.main(Native Method)
06-04 15:50:52.814: E/AndroidRuntime(23237): Caused by: java.lang.NullPointerException
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.widget.TabHost.addTab(TabHost.java:236)
06-04 15:50:52.814: E/AndroidRuntime(23237): at tbjsoft.enclosurecalculator.DiagramTabHost.onCreate(DiagramTabHost.java:37)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.Activity.performCreate(Activity.java:5104)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-04 15:50:52.814: E/AndroidRuntime(23237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-04 15:50:52.814: E/AndroidRuntime(23237): ... 11 more
这是第一个标签主机
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_host);
build();
}
public void build(){
vas = getIntent().getDoubleExtra("vas",0);
fs = getIntent().getDoubleExtra("fs",0);
qts = getIntent().getDoubleExtra("qts",0);
qes = getIntent().getDoubleExtra("qes",0);
slotWidth = getIntent().getDoubleExtra("slotWidth",0);
slotHeight = getIntent().getDoubleExtra("slotHeight",0);
portDiameter = getIntent().getDoubleExtra("portDiameter",0);
sVolume = getIntent().getDoubleExtra("sealedVolume",0);
pVolume = getIntent().getDoubleExtra("portedVolume",0);
fb = getIntent().getDoubleExtra("fb", 0);
tabHost = getTabHost();
spec = tabHost.newTabSpec("Specs");
spec.setIndicator("Specs");
Intent calculate = new Intent(this, Calculate.class);
calculate.putExtra("vas", vas);
calculate.putExtra("fs", fs);
calculate.putExtra("qts", qts);
calculate.putExtra("qes", qes);
calculate.putExtra("slotWidth", slotWidth);
calculate.putExtra("slotHeight", slotHeight);
calculate.putExtra("portDiameter", portDiameter);
spec.setContent(calculate);
dimensions = tabHost.newTabSpec("Dimensions");
dimensions.setIndicator("Dimensions");
Intent dimension = new Intent(this,BoxDimensions.class);
dimension.putExtra("sVolume",sVolume);
dimension.putExtra("pVolume",pVolume);
dimensions.setContent(dimension);
ports = tabHost.newTabSpec("Ports");
ports.setIndicator("Ports");
Intent port = new Intent(this, Ports.class);
port.putExtra("fb", fb);
port.putExtra("pVolume", pVolume);
ports.setContent(port);
tabHost.addTab(spec);
tabHost.addTab(dimensions);
tabHost.addTab(ports);
}
}
这是第二个
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagram_tab_host);
tabHost = (android.widget.TabHost) findViewById(R.id.wdTabHost);
in = getIntent().getStringArrayListExtra("imageName");
if(in.get(4).equals("1")){
String imageName = in.get(0) + in.get(1) + in.get(2) + in.get(3) + in.get(4);
diagram = tabHost.newTabSpec("Diagram");
diagram.setIndicator("Diagram");
Intent d = new Intent(DiagramTabHost.this, Diagram.class);
d.putExtra("imageName",imageName);
diagram.setContent(d);
tabHost.addTab(diagram);
}else{
String imageName = in.get(0) + in.get(1) + in.get(2) + in.get(3) + in.get(4);
parallel = tabHost.newTabSpec("Parallel");
parallel.setIndicator("Parallel");
Intent p = new Intent(DiagramTabHost.this, Parallel.class);
p.putExtra("imageName",imageName);
parallel.setContent(p);
series = tabHost.newTabSpec("Series");
series.setIndicator("Series");
Intent s = new Intent(DiagramTabHost.this, Series.class);
s.putExtra("imageName",imageName);
series.setContent(s);
tabHost.addTab(parallel);
tabHost.addTab(series);
}
}