Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid -- Visible and Invisible Tabs: Button Handling
    primarykey
    data
    text
    <p>I am trying to create an application with a login screen that appears and has effects among various other tabs.</p> <p>I have the tabbed implementation working fine: I can hide tabs and view the layouts of other tabs -- however, I cannot make them reappear. The program runs fine when I do not attempt button handling, but whenever I start my listener, I force-close.</p> <p>Attached is the problem code: I can't find exactly where I'm getting the force close from, but I do know it is in the button listener area.</p> <p>Essentially, I want the tabs to appear if the user's name and password are correct.</p> <p>What you are seeing is one of four tabs. Specifically, you are looking at the login screen tab.</p> <p>CODE:</p> <pre><code>public class LoginActivity extends Activity { TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); final Button btn = (Button) findViewById(R.id.login_button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText txt_username = (EditText) findViewById(R.id.txt_username); EditText txt_password = (EditText) findViewById(R.id.txt_username); if (txt_username.toString().equals("Bob") &amp;&amp; txt_password.toString().equals("123")) { tabHost.getTabWidget().getChildAt(0) .setVisibility(View.VISIBLE); tabHost.getTabWidget().getChildAt(1) .setVisibility(View.VISIBLE); tabHost.getTabWidget().getChildAt(2) .setVisibility(View.VISIBLE); tabHost.getTabWidget().getChildAt(3) .setVisibility(View.GONE); } } }); } } </code></pre> <p>Attached is the logcat (very long)</p> <pre><code>04-12 17:07:31.465: ERROR/AndroidRuntime(1480): FATAL EXCEPTION: main 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.waiter/android.waiter.waiter}: java.lang.RuntimeException: Unable to start activity ComponentInfo{android.waiter/android.waiter.LoginActivityGroup}: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{android.waiter/android.waiter.LoginActivity}: java.lang.NullPointerException 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at android.os.Handler.dispatchMessage(Handler.java:99) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at android.os.Looper.loop(Looper.java:123) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at android.app.ActivityThread.main(ActivityThread.java:4627) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at java.lang.reflect.Method.invokeNative(Native Method) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at java.lang.reflect.Method.invoke(Method.java:521) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-12 17:07:31.465: ERROR/AndroidRuntime(1480): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload