I am calling a simple onclicklistener on a button but the call to launch.setonclickListner results in force close exception.. if i remove the onclicklistener on button my login page is displayed otherwise as soon as i start my application i get a dialog window saying Sorry, application closed unexpectedly..
Mt activity class:
public class loginActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// load up the layout
setContentView(R.layout.main);
// get the button resource in the xml file and assign it to a local variable of type Button
Button launch = (Button)findViewById(R.id.login_button);
launch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(loginActivity.this, "Couldn't find the 'txt_username' or 'txt_password'",
Toast.LENGTH_SHORT).show();
}
});
}
}
12-23 19:39:55.712: DEBUG/AndroidRuntime(772): Shutting down VM
12-23 19:39:55.712: WARN/dalvikvm(772): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
12-23 19:39:55.712: ERROR/AndroidRuntime(772): Uncaught handler: thread main exiting due to uncaught exception
12-23 19:39:55.723: ERROR/AndroidRuntime(772): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nagarro.urbanSignals/com.nagarro.urbanSignals.loginActivity}: java.lang.NullPointerException
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2268)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2284)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.app.ActivityThread.access$1800(ActivityThr ead.java:112)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.app.ActivityThread$H.handleMessage(Activit yThread.java:1692)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.os.Handler.dispatchMessage(Handler.java:99 )
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.os.Looper.loop(Looper.java:123)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.app.ActivityThread.main(ActivityThread.jav a:3948)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at java.lang.reflect.Method.invoke(Method.java:521)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:782)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:540)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at dalvik.system.NativeStart.main(Native Method)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): Caused by: java.lang.NullPointerException
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at com.nagarro.urbanSignals.loginActivity.onCreate(lo ginActivity.java:23)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1123)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2231)
12-23 19:39:55.723: ERROR/AndroidRuntime(772): ... 11 more
12-23 19:39:55.743: INFO/Process(564): Sending signal. PID: 772 SIG: 3
12-23 19:39:55.743: INFO/dalvikvm(772): threadid=7: reacting to signal 3
12-23 19:39:55.743: INFO/dalvikvm(772): Wrote stack trace to '/data/anr/traces.txt'
12-23 19:39:59.924: INFO/Process(772): Sending signal. PID: 772 SIG: 9
12-23 19:39:59.933: INFO/ActivityManager(564): Process com.nagarro.urbanSignals (pid 772) has died.
12-23 19:40:00.253: WARN/InputManagerService(564): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$ Proxy@4375b888
--------------------------------------------------------------
Please suggest sumthing to workaround the problrm......