aspose file tools*
The moose likes Beginning Java and the fly likes passing variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "passing variables" Watch "passing variables" New topic
Author

passing variables

emma quinn
Greenhorn

Joined: Feb 13, 2003
Posts: 4
hi people
I have a BigInteger variable bigInt1 holding a value in GetNode class. I need to be able to pass this variable still holding that value into another class - the RegisterNode class. When I try using that variable in RegisterNode, I just get null pointer exceptions. The RegisterNode class is already inheriting the GetNode class. I have my main set up as follows...not sure if this has anything to do with it.

bigInt1 is declared globally and is held in a public method in the GetNode class.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
When you state "bigInt1 is declared globally and is held in a public method in the GetNode class", what do you mean? Java does not allow for the declaration of global variables within methods (they have to be static members of classes).
If you could post your code where you attempt to get and set the value of the bigInt1 variable we would better be able to help.
Thanks,


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
emma quinn
Greenhorn

Joined: Feb 13, 2003
Posts: 4
It's declared here:

and used here:

the values of the BigIntegers then need to get passed into another class (RegisterNode). In the RegisterNode class, for now anyway, to test if the value of the BigIntegers can be seen I'm just performing a System.out, but it's returning null pointer.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
How is the RegisterNode class accessing the pubBigInt1 variable?
Your variables are not global variables; they are member variables of your GetNode class. In order for the RegisterNode instance to access those variables, you would have to pass the instance of the GetNode class containing them.
Then, you would say:

...of course, my OO instincts kick in here and say that it's better to have your GetNode class provide read and write methods (getPubBigInt1 and setPubBigInt1) instead of letting other classes access those members directly.
And (again, this is my OO instincts telling me I should mention this), it seems as though your class names should be revised a little. I know there's a standard way of naming them but I'm too lazy to look it up right now To me, though, a class chould be named <Noun> and methods named <Verb>[DirectObject]. This way, a method call reads like a sentence: <Noun>.<Verb>[DirectObject](<prepositional phrases>|<adjetive>|<adverb>|<however-you-want-to-think-of-parameters>) ;
Thus, "GetNode" and "RegisterNode" sound like methods, not classes. "NodeGetter" and "NodeRegistrar" sound more like class names
[ May 21, 2003: Message edited by: Joel McNary ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
RegisterNode sounds like a good class name to me. Remember that Register is a noun, as well as a verb. I agree that GetNode doesn't sound like a good class name since the word "get" can be nothing except a verb. As Joel mentioned, classes are usually named with nouns whereas functions are named with verbs.


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing variables
 
Similar Threads
Trees with arbitrary node pointers
instance final variables
use of interfaces
How to print the tag element along with the value
Turning JTree into a layout manager, resizing nodes