为啥一tabhost.setup();就崩了?
package com.example.tabhost; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.widget.TabHost; public class MainActivity extends Activity { private TabHost tabhost; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i("14", "start"); setContentView(R.layout.activity_main); Log.i("15", "start"); tabhost = (TabHost)findViewById(R.id.tabhost); Log.i("17", "start"); // 为啥一运行到这就崩了? tabhost.setup();//初始化 Log.i("20", "start"); LayoutInflater inflater = LayoutInflater.from(this);//实例化 Log.i("21", "start"); inflater.inflate(R.layout.first, tabhost.getTabContentView()); inflater.inflate(R.layout.second, tabhost.getTabContentView()); inflater.inflate(R.layout.third, tabhost.getTabContentView()); Log.i("25", "start"); tabhost.addTab(tabhost.newTabSpec("tab01") .setIndicator("第一个tab") .setContent(R.id.tab01)); tabhost.addTab(tabhost.newTabSpec("tab02") .setIndicator("第二个tab") .setContent(R.id.tab02)); tabhost.addTab(tabhost.newTabSpec("tab03") .setIndicator("第三个tab") .setContent(R.id.tab03)); Log.i("27", "start"); } }
解决方案:20分
贴错误信息,报的是空,还是什么。