我在上下文中的含义 ::我在这里设置了Sherlock操作栏标签
我想做什么 ::
MainActivity.java
public class MainActivity extends SherlockFragmentActivity {
// Declare Variables
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the view from main_fragment.xml
setContentView(R.layout.main_fragment_desc_list_view);
// Locate android.R.id.tabhost in main_fragment.xml
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
// Create the tabs in main_fragment.xml
mTabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
// Create Tab1 with a custom image in res folder
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Rating"),
SortByRatingDescListView.class, null);
// Create Tab2
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Price"),
SortByPriceDescListView.class, null);
}
}
注意 ::代码功能正常,无需添加以下代码行(降低高度)
我尝试了 ::
//Setting custom height for the tabs
final int height = 45;
mTabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
mTabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
但我收到的错误为 ::
01-31 15:40:58.270: E/AndroidRuntime(367): FATAL EXCEPTION: main
01-31 15:40:58.270: E/AndroidRuntime(367): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.findmybuffet/com.findmybuffet.restaurant_module.MainActivity}: java.lang.NullPointerException
01-31 15:40:58.270: E/AndroidRuntime(367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.os.Handler.dispatchMessage(Handler.java:99)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.os.Looper.loop(Looper.java:123)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-31 15:40:58.270: E/AndroidRuntime(367): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 15:40:58.270: E/AndroidRuntime(367): at java.lang.reflect.Method.invoke(Method.java:521)
01-31 15:40:58.270: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-31 15:40:58.270: E/AndroidRuntime(367): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-31 15:40:58.270: E/AndroidRuntime(367): at dalvik.system.NativeStart.main(Native Method)
01-31 15:40:58.270: E/AndroidRuntime(367): Caused by: java.lang.NullPointerException
01-31 15:40:58.270: E/AndroidRuntime(367): at com.findmybuffet.restaurant_module.MainActivity.onCreate(MainActivity.java:24)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-31 15:40:58.270: E/AndroidRuntime(367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-31 15:40:58.270: E/AndroidRuntime(367): ... 11 more
谢谢,