Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2008
    Posts
    64
    Rep Power
    0

    Default problem in getter method

    Hi,
    Below is the code i used..

    public String getSearch_text() {
    System.out.println("search text in To get>>>>>>>>>>>"+ search_text);
    return search_text;
    }

    public void setSearch_text(String search_text) {
    this.search_text = search_text;
    System.out.println("search text in To set>>>>>>>>>>>"+search_text);
    }

    and the output in the console is..

    search text in To set>>>>>>>>>>>cancer
    search text in To get>>>>>>>>>>>null

    which means.. the String search_text is setting but there is some problem in getter method..
    can anyone find out what is making the problem..

    Regards,
    freddie

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    try to print this.search_text

    can you show us the code? if it is not long....
    freedom exists in the world of ideas

  3. #3
    Join Date
    Apr 2008
    Posts
    64
    Rep Power
    0

    Default

    hi sukatoa,

    this.search_text is also getting printed...

    the code is used is,
    String search_text=search_to.getSearch_text();
    System.out.println("in service search text>>>>>>>>>>"+search_text);

    search_to.setLinks(links);
    System.out.println("links in the dao>>>>>>>>>>>>>>"+links);


    Not only this variable but all variables in my application, the setter method is successfully happening however am finding problem only in the getter method..

    I mean, in the code which is in the top of this pagae, SOP of setter is fine but SOP of getter method always show null....... very strange problem.. donno wats exactly the problem..

    output that i got is below,
    in service search text>>>>>>>>>>null
    links in the dao>>>>>>>>>>>>>>CANCER


    regards
    Last edited by freddieMaize; 05-25-2008 at 11:49 AM.

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    I think that is not strange, (for me)

    Please correct me,
    Is that setter/getter methods are in other class? right?
    That problem may occur if you initialize a new object of that class and invoking the getter method which returns a null....

    For example,

    If you've created an instance of a class that has setter/getter method, you could only capture the value being stored if you also use that instance(object) for getting its value stored...

    Java Code:
    public class Class1{
    
           String value=null;
    
           public void setter(String v){
                 value=v;
           }
           
           public String getter(){
                 return value;
           }
    }
    here's the testers

    tester 1
    Java Code:
    public class tester{
    
          Class1 c = new Class1();
          
          public static void main(String sukatoa[]){
                 new tester();
          }
    
          public tester(){
                c.setter("I AM WHO AM");
                System.out.println(c.getter());
          }
    }
    tester 2
    Java Code:
    public class tester{
    
          Class1 c = new Class1();
          
          public static void main(String sukatoa[]){
                 new tester();
          }
    
          public tester(){
                c.setter("I AM WHO AM");
                c=new Class1(); //Maybe this is what you should avoid to get the value that was being set.
                System.out.println(c.getter());
          }
    }
    Try to test the ff. codes, i haven't test them yet, but hopefully successful....

    tester 2 should be the problem like yours,
    tester 1 should show the String being stored...
    Last edited by sukatoa; 05-25-2008 at 03:49 PM.
    freedom exists in the world of ideas

  5. #5
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    hey freddie, can you post the code of your bean/databindbean [ getter/setter class ]
    i am the future

  6. #6
    Join Date
    Apr 2008
    Posts
    64
    Rep Power
    0

    Default

    Quote Originally Posted by sukatoa View Post
    Is that setter/getter methods are in other class? right?
    That problem may occur if you initialize a new object of that class and invoking the getter method which returns a null....
    Yes Sukatoa.. what you said is exactly correct.. They reside in different class.. New object ll return null..
    But my args. is, the object is a singleton object.. that's why i said it was strange..

    I used the below,
    this is to.xml.. here the object is a singelton by default....

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">      
     <bean id="search_to" class="Autonomy_To.Search_To"/>
    </beans>
    and this is how i use the object in my application..
    Java Code:
        ApplicationContext cxt_to = new ClassPathXmlApplicationContext("Autonomy_To/to.xml");
        Search_To search_to =  (Search_To) cxt_to.getBean("search_to");
    so there is no replication of object...... (i hope)......

    Rjuyal, what is that you exactly asked for.. is that the entire form bean code??

    Regards
    Last edited by freddieMaize; 05-26-2008 at 08:05 AM.

Similar Threads

  1. Replies: 2
    Last Post: 03-26-2010, 06:12 PM
  2. problem with split method
    By abhiN in forum New To Java
    Replies: 7
    Last Post: 02-10-2009, 02:54 PM
  3. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 09:37 AM
  4. How To Add Fields And Generating Getter-Setters
    By JavaForums in forum NetBeans
    Replies: 0
    Last Post: 07-31-2007, 12:13 AM
  5. Problem with sort method
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 08:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •