如何在CordovaActivity中使用TabHost?

时间:2016-01-28 17:41:52

标签: java android cordova android-tabhost

我有这个示例cordova应用程序,我正在尝试添加TabHost。当我运行它时,它崩溃了,logcat说:

  

java.lang.RuntimeException:无法开始活动   ComponentInfo {io.cordova.hellocordova/io.cordova.hellocordova.MainActivity}:   java.lang.NullPointerException: 尝试调用虚方法' void   android.widget.TabHost.setup()'在空对象引用上

这是我的班级:

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        Resources ressources = getResources();
        TabHost tabs = (TabHost)this.findViewById(R.id.tabhost);
        tabs.setup();

        Intent intentAndroid = new Intent().setClass(this, Utilitites.class);
        TabSpec tabSpecAndroid = tabs
                .newTabSpec("Utilities")
                .setIndicator("", ressources.getDrawable(R.drawable.ic_delete))
                .setContent(intentAndroid);

        // Apple tab
        Intent intentApple = new Intent().setClass(this, Locations.class);
        TabSpec tabSpecApple = tabs
                .newTabSpec("Locations")
                .setIndicator("", ressources.getDrawable(R.drawable.ic_delete))
                .setContent(intentApple);

        tabs.addTab(tabSpecAndroid);
        tabs.addTab(tabSpecApple);

        // Set by <content src="index.html" /> in config.xml
        // loadUrl(launchUrl);
    }
}

这是因为班级没有扩展TabActivity。如果我这样做,那么我就无法运行cordova activity命令loadUrl(launchUrl)

有没有办法在TabHost中使用CordovaActivity

0 个答案:

没有答案