I am trying to create an application with a login screen that appears and has effects among various other tabs.
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.
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.
Essentially, I want the tabs to appear if the user's name and password are correct.
What you are seeing is one of four tabs. Specifically, you are looking at the login screen tab.
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")
&& 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);
}
}
});
}
}
Attached is the logcat (very long)
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)