Android Application in TAB HOST TabActivity can't Start
-
package com.tabs; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.TabHost; import android.widget.TabHost.TabSpec; @SuppressWarnings({ "unused", "deprecation" }) public class MainActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); Resources res = getResources(); TabHost th = getTabHost(); Intent tb1 = new Intent().setClass(this, New_User.class); TabSpec tbs1 = th.newTabSpec("New_user").setIndicator("NEW USER", null) .setContent(tb1); Intent tb2 = new Intent().setClass(this, Login_user.class); TabSpec tbs2 = th.newTabSpec("login").setIndicator("LOGIN", null) .setContent(tb2); th.addTab(tbs1); th.addTab(tbs2); th.setCurrentTab(0); } }
-
package com.tabs; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.TabHost; import android.widget.TabHost.TabSpec; @SuppressWarnings({ "unused", "deprecation" }) public class MainActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); Resources res = getResources(); TabHost th = getTabHost(); Intent tb1 = new Intent().setClass(this, New_User.class); TabSpec tbs1 = th.newTabSpec("New_user").setIndicator("NEW USER", null) .setContent(tb1); Intent tb2 = new Intent().setClass(this, Login_user.class); TabSpec tbs2 = th.newTabSpec("login").setIndicator("LOGIN", null) .setContent(tb2); th.addTab(tbs1); th.addTab(tbs2); th.setCurrentTab(0); } }
So what exactly is your question? Have you single-stepped through the code using the debugger? Have you considered checking return values from function calls, or maybe surrounding the code with a
try
/catch
block? :doh:"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
package com.tabs; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.TabHost; import android.widget.TabHost.TabSpec; @SuppressWarnings({ "unused", "deprecation" }) public class MainActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); Resources res = getResources(); TabHost th = getTabHost(); Intent tb1 = new Intent().setClass(this, New_User.class); TabSpec tbs1 = th.newTabSpec("New_user").setIndicator("NEW USER", null) .setContent(tb1); Intent tb2 = new Intent().setClass(this, Login_user.class); TabSpec tbs2 = th.newTabSpec("login").setIndicator("LOGIN", null) .setContent(tb2); th.addTab(tbs1); th.addTab(tbs2); th.setCurrentTab(0); } }
Hello, I had similar problem. Please see my example: 1) Xml file (note android.support.v4 is used):
- Java file for Activity:
MainActivity extends FragmentActivity
implements YourFirstFragment.OnFragmentInteractionListener, YourSecondFragment.OnFragmentInteractionListener{
private FragmentTabHost _yourTabHost;protected void onCreate(Bundle savedInstanceState)
{
_yourTabHost =(FragmentTabHost)findViewById(android.R.id.tabhost);
_yourTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);_yourTabHost.addTab(_mTabHost.newTabSpec("first_fragment").setIndicator("NameOnTab"), YourFirstFragment.class, null);
_yourTabHost.addTab(_mTabHost.newTabSpec("second_fragment").setIndicator("NameOnTab"), YourSecondFragment.class, null);
}
}Hope this will help somehow.