我正在为我的应用程序进行更新,我刚刚添加了另一个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
这是第一个tabhost
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);
}
}
答案 0 :(得分:0)
我认为问题是如果使用setup()
加载TabHost,则需要在添加标签之前调用findViewById()
。
tabHost = (android.widget.TabHost) findViewById(R.id.wdTabHost);
tabHost.setup();
我基本上直接引用documentation。
答案 1 :(得分:0)
我试图在我的应用程序[“Droid Bones”]中这样做但没有成功。如果在Android设备中安装“Droid Bones”,则可以看到我的解决方法结构。