アプリの更新に取り組んでおり、別のタブホストを追加したばかりですが、エラーが発生し続けます。最初のタブホスト アクティビティは、TabActivity を拡張します。2番目のものでそれをやろうとしましたが、うまくいかなかったので、拡張アクティビティに戻りました. その後、他のエラーが発生し始めました。logcat を見ていましたが、エラーの 1 つが最初のタブホスト アクティビティを参照していたので、それについて少し混乱しています。私は何をすべきかわからない。
ログキャットはこちら
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);
}
}
2つ目はこちら
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);
}
}