File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Java 8 in Action this week in the Java 8 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: 33

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: 39576
    
  27
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 - updated with new look and Ping home screen widget
udaya krishna
Ranch Hand

Joined: Mar 19, 2009
Posts: 33

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: 39576
    
  27
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: 33

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
 
Similar Threads
CMT NOT_SUPPORTED and REQUIRED transactional behavior
Looking for Java help.
strange problem with final keyword
how to create new textbox on clicking of a button
How to destroy the application completely?