Forums Register Login

Passing values to constructor

+Pie Number of slices to send: Send
I will post all code in a follow on. In the interest of space, I have only
posted portions here. I am trying to pass values from one class if the
button is pressed to another class' constructor. I am clearly not doing
this correctly.

Thanks for your help.


_______________________________________


I'll post both class files below but hopefully this text is enough to
figure out what is wrong.

Thanks!
[ May 24, 2005: Message edited by: Gregg Bolinger ]
+Pie Number of slices to send: Send
Here is all of the code in both classes.


Here is the second class


[Gregg Bolinger - Edited to fix page width problems.]
[ May 24, 2005: Message edited by: Gregg Bolinger ]
+Pie Number of slices to send: Send
The method you are using to pass values to the constructor is fine.

What problems are you experiencing? Are you using the passed in values correctly? Why is your userID and password null?

Maybe you need to do:
String userID = uNameString ;
String password = pWordString ;
+Pie Number of slices to send: Send
Fahd,

The userID and password are "null" because they are not required to
log into the DB. The reason for passing the values is for use in the
query "SELECT FirstName, LastName FROM CUS_USER (the table)
WHERE EmailAddress = 'uNameString' (first string) AND Pasword =
'pWordString'(the second string)";

But, when I compile, I get the following error:
"TestMainScreen.java:67: cannot find symbol
symbol: constructor TestLogin(java.lang.String,java.lang.String)
location: class TestLogin
TestLogin tl = new TestLogin(uNameString, pWordString);
^
1 error
+Pie Number of slices to send: Send
The carrot in the preceding should be under new BTW.
+Pie Number of slices to send: Send
Fixed it by playing around... here is how:

+Pie Number of slices to send: Send
Some questins and comments.

Why is there a main method in your TestLogin class and why does it extend JFrame?

String uNameString = "null";
String pWordString = "null";

That does not set those variables to null. That sets those variables to a string value that equals a literal string null. You probably meant to do:

String uNameString = null;
String pWordString = null;

Let's look at what you are trying to do but much simpler.



+Pie Number of slices to send: Send
Gregg,

The simple answer is: I don't know... I just kept trying things until
it worked. Not very scientific to be sure.

I extended JFrame in that class only to create a new screen. I am sure
that is not the right way to go about it which is why I have found
this forum to be so very valuable. I have gotten more to work in the
last four days due to you and Ernest's help than I have ever understood
in the past. Please keep the comments coming. What I generally do is
get the thing to just work. That is all I care about. After I do that,
I try some other things (play with the code and see what breaks it and
what makes it work with less code). For instance, I did not even try
to pass these values and create a new object until I got both classes
working all by themselves. Once I tried that, it broke. Then I tried a
whole bunch of things until it worked again. Once you give me feedback,
I make leeps and bounds. It is funny that so many of the things that I am
told after I try the dumb way just seems so obvious later on. This forum
has been outstanding for helping me learn.


+Pie Number of slices to send: Send
I gotta ask ... do you get a lot of "Al wells that end wells" ??
+Pie Number of slices to send: Send
All through my childhood and still to this day. What is worse is that my
name is short for Alvin. My parents were high when I was born. I wonder if
it is too late to switch to using my middle name...

+Pie Number of slices to send: Send
 

Originally posted by Al Wells:
The carrot in the preceding should be under new BTW.



That typo made my day, I'm still grinning - thanks!

If you want to preserve the formatting of your text, for example for positioning carets, you need to use code tags.
Do you pee on your compost? Does this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2611 times.
Similar Threads
Triangle Problem
JDialog modality issue on Win7 taskbar click
scoured the net for reusable ftp program but having problems
NullPointerException
Inner not knowing about outer
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:53:15.