我有一个带有以下 onCreate 方法的 FragmentActivity,它似乎在使用 Android 2.1 或更低版本的移动设备上崩溃。关于可能导致此错误的任何想法?
启动此活动时引发的异常:
04-25 20:00:41.834: E/AndroidRuntime(381): Uncaught handler: thread main exiting due to uncaught exception
04-25 20:00:41.877: E/AndroidRuntime(381): java.lang.NullPointerException
04-25 20:00:41.877: E/AndroidRuntime(381): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.view.ViewRoot.handleMessage(ViewRoot.java:1819)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.os.Looper.loop(Looper.java:123)
04-25 20:00:41.877: E/AndroidRuntime(381): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-25 20:00:41.877: E/AndroidRuntime(381): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 20:00:41.877: E/AndroidRuntime(381): at java.lang.reflect.Method.invoke(Method.java:521)
04-25 20:00:41.877: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-25 20:00:41.877: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-25 20:00:41.877: E/AndroidRuntime(381): at dalvik.system.NativeStart.main(Native Method)
我的 FragmentTabs 课程的一部分
public class FragmentTabs extends SherlockFragmentActivity
{
protected static final int RESULT_CLOSE_APPLICATION = 666;
protected static final int RESULT_RESET_USER = 667;
LoginController loginControl;
Context ctx;
Fragment lastFragment;
int initRun;
boolean isRoot;
/**
* Decklare tabs and associate them with their respective initial fragments.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_tabs);
ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayShowHomeEnabled(false);
bar.setDisplayShowTitleEnabled(false);
ActionBar.Tab tabA = bar.newTab().setText("Forside");
ActionBar.Tab tabB = bar.newTab().setText("Indstil");
ActionBar.Tab tabC = bar.newTab().setText("Mere");
tabA.setTabListener(new MyTabsListener(new FrontpageFragment()));
tabB.setTabListener(new MyTabsListener(new SettingsFragment()));
tabC.setTabListener(new MyTabsListener(new MoreFragment()));
bar.addTab(tabA);
bar.addTab(tabB);
bar.addTab(tabC);
}
我尝试了此处提供的答案,但我认为该解决方案不适用于我的应用程序。我确实认为它与“标签栏”有关。