This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Android and the fly likes Method not getting called inside an activity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Method not getting called inside an activity" Watch "Method not getting called inside an activity" New topic
Author

Method not getting called inside an activity

udaya krishna
Ranch Hand

Joined: Mar 19, 2009
Posts: 45

Hi All,

I have just started to learn android by building very small and simple applications.I have created a simple app with 2 textboxes(edittext) and two buttons"Login" and "Add User".Currently I am not doing anything on click of "Login" button.But on click of "Add user" button, i am loading another screen from MainActivity.java by calling
which is activity_main_user.xml which contains a series of textboxes and a "Save" button.I have written a method in AddUserActivity.java which currently just displays a message.But the problem is that logcat is throwing an exception saying it could not find saveUser() method in MainActivity.java.I have written the method in AddUserActivity.java , so how do i call the saveUser() method written in activity_main_user.xml ? Should i create a new activity from within MainActivity? The issue might be very basic one since i have just started learning.Please let me know where am i going wrong?

Regards
Udaya Krishna.A
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41631
    
  55
Are you explicitly starting the AddUserActivity? Just setting the activity_add_user layout does not start a new activity. The layout should be set in the onCreate method of the AddUserActivity class.

Also, what does "how do i call the saveUser() method written in activity_main_user.xml" mean? Methods are defined in classes, not layout files.


Ping & DNS - my free Android networking tools app
udaya krishna
Ranch Hand

Joined: Mar 19, 2009
Posts: 45

Hi Ulf,
Thanks for the response
Methods are defined in classes, not layout files.
I am sorry that was a big typo !!Yes , i have defined the method in AddUserActivity.java , i have a button in activity_add_user.xml which should call save() method of AddActivityUser.java , based on some online help i found out that i have to create an Intent in MainActivity and then call the startActivity() method. Let me know if the approach is correct.

Thanks
Uday
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41631
    
  55
That sounds basically correct. Seeing some relevant excerpts of the code might help us understand what is (or is not) going on. Please UseCodeTags for that.
udaya krishna
Ranch Hand

Joined: Mar 19, 2009
Posts: 45

Thank you Ulf for the help.Its working now as i created a new activity..i am sure plenty more silly issues might get posted by me in future
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Method not getting called inside an activity