Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Passing Value from 1 class 2 another

 
Ranch Hand
Posts: 158
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All

I m a new user of java.

plz help me out 2 solve my problem.

1 class = dbconnection
2 class = util
3 class = company
4 class = login

i ve connected database with dbconnection in login form using
dbconnection conn = new dbconnection();

then userid is asked. When i enter my login it passes value to util class
util u = new util(); // this is initialized at top.
u.setValue(txtUserId.getText());

public String setValue(String str)
{ String myVal
myVal = str;
System.out.println(myVal);
return myVal;
}

when i m trying to print that value i is showing user id.

I ve a button on login form called "Company".
I ve inititlized util object at the top.

util abc = new util();

Problem:
========
i want to get the value that i ve assigned in my login form using setValue() method.

But when ever i m getting value from util class it shows null value;
Plz tell where i m wrong?

ANAND
 
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check on
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are attempting to perform a util.getValue() to fetch the value after it is set, you will not get a value since you initialized the myVal String within your util.setValue(String str) method. In order to retrieve this value, you will have to create a class member that you would populate in the setValue(String str) method and retrieve via the getValue() method
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a duplicate of another post.
 
reply
    Bookmark Topic Watch Topic
  • New Topic