Android Forums

Go Back   Android Forums > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
Reply
 
LinkBack Thread Tools Display Modes
Old 12-23-2009, 08:58 AM   #1
Junior Member
 
Join Date: Dec 2009
Posts: 4
Friends: 0
View Anjul's Profile   View Anjul's Photo Album   View Anjul's Blog   View Social Groups
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......
Anjul is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Old 01-02-2010, 03:32 PM   #2
Junior Member
 
Join Date: Jan 2010
Location: Palo Alto, CA
Posts: 1
Friends: 0
View jwei512's Profile   View jwei512's Photo Album   View jwei512's Blog   View Social Groups
According to the logs it seems like there's a null pointer exception.

Are you sure you defined R.id.login_button in your main.xml? If not, then Button launch will get returned as null and hence your problem.
jwei512 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Reply

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Call waiting, switching from call to call tazz Droid 2 01-27-2011 06:03 PM
Yet another problem with button layout... rvaul Android Development, Answers, Tutorials, and Code Snippets 2 11-28-2009 11:07 AM
Q. Update all application/button? Is there… matt172001 Android Games And Applications 0 11-18-2009 01:19 PM
G1 Camera button HALP misspriss G1 6 05-11-2009 08:50 PM
Volume button switching? justinrobert Android Hardware 2 03-12-2009 12:35 PM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 09:57 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.