タブを作成してフラグメントを追加したいのですが、Tabspec をタブに追加しているときにクラッシュします。ソースはこちら、
mTabHost = (TabHost)findViewById(android.R.id.tabhost);
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent().setClass(this, DummyFrag.class);
spec = mTabHost.newTabSpec("artists").setIndicator("Numbers").setContent(intent);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(android.R.id.tabcontent);
if (fragment == null)
{
FragmentTransaction ft = fm.beginTransaction();
ft.add(android.R.id.tabcontent, new DummyFrag(),"DummyFrag");
// m_mainactivity.getSupportActionBar().selectTab(curTab);
ft.commit();
}
mTabHost.addTab(spec);
}
public static class DummyFrag extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.dummy, container, false);
return view;
}
}
問題の正確な場所を教えてください。事前に感謝します
猫の詳細を記録する
06-16 11:11:15.797: E/AndroidRuntime(461): java.lang.RuntimeException: Unable to start activity ComponentInfo{simple.preview.screen/simple.preview.screen.SimplePreviewActivity}: java.lang.NullPointerException
06-16 11:11:15.797: E/AndroidRuntime(461): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.os.Looper.loop(Looper.java:123)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-16 11:11:15.797: E/AndroidRuntime(461): at java.lang.reflect.Method.invokeNative(Native Method)
06-16 11:11:15.797: E/AndroidRuntime(461): at java.lang.reflect.Method.invoke(Method.java:521)
06-16 11:11:15.797: E/AndroidRuntime(461): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-16 11:11:15.797: E/AndroidRuntime(461): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-16 11:11:15.797: E/AndroidRuntime(461): at dalvik.system.NativeStart.main(Native Method)
06-16 11:11:15.797: E/AndroidRuntime(461): Caused by: java.lang.NullPointerException
06-16 11:11:15.797: E/AndroidRuntime(461): at android.widget.TabHost.addTab(TabHost.java:209)
06-16 11:11:15.797: E/AndroidRuntime(461): at simple.preview.screen.SimplePreviewActivity.onCreate(SimplePreviewActivity.java:50)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-16 11:11:15.797: E/AndroidRuntime(461): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)