• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Method not getting called inside an activity

 
Ranch Hand
Posts: 69
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43076
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
udaya krishna
Ranch Hand
Posts: 69
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43076
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Do you want ants? Because that's how you get ants. And a tiny ads:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic