Results 1 to 11 of 11
Thread: Need help with get function
- 11-09-2008, 05:33 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 13
- Rep Power
- 0
-
First -- what does your Vector hold? Is it Integer objects? If so, and if you have to use Java 4 or before, you'll have to get the int value of the Integer. If it's something else, you'll still need to translate it into a number before Java will allow you to add it to an int.
- 11-09-2008, 05:58 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 13
- Rep Power
- 0
The vector contains integers. I am using Eclipse 3.3.2 I am not sure if that is what you are looking for. I am trying to get an integer that is in the vector at position x, then add it to another integer.
-
The problem may be that the Vector holds Integer objects and you want to add it to a primitive int. If the Vector is not a generic Vector, in other words not declared Vector<Integer>, you will need to do the conversion yourself. Something like this may work:
Java Code:int vectorInt = ((Integer)myVector.get(i)).intValue(); // cast object returned from Vector to Integer and call intValue() to convert to int primitive int sum = vectorInt + otherInt;
- 11-09-2008, 06:18 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 13
- Rep Power
- 0
That worked. Thanks. One more quick question. If I have a two classes in different packages how can I access methods in one class from one in a different package.
- 11-09-2008, 06:35 PM #6
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
I believe you must import the class to be used, and the method to be used must be public.
- 11-09-2008, 06:44 PM #7
Member
- Join Date
- Nov 2008
- Posts
- 13
- Rep Power
- 0
I don't know how to import a class. Could you tell me how to do this?
Thanks a bunch.
- 11-09-2008, 06:48 PM #8
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
I assumed that you already know how to import the Vector class. You'd just do the same for the one you're trying to use. A quick Google search gave me this link: Java: Packages and Import
- 11-09-2008, 06:57 PM #9
Member
- Join Date
- Nov 2008
- Posts
- 13
- Rep Power
- 0
I think we might be thinking of different things. In my program I have created two packages: cards and participant. I need a method from a class in the cards package, in a class in the participant package. This is unrelated to the vector question I had earlier.
Another way of wording it might be like this.
I have class A in package X and class B in package Y. How can i make an A object in the B class?
Thanks
- 11-09-2008, 07:13 PM #10
A anA = new A(); // make an A object
You'll need an import X.A; to get the A class definition. And you'll need the classpath set to the folder containing the X folder.
- 11-09-2008, 07:59 PM #11
Member
- Join Date
- Nov 2008
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Need a little help with a function!
By Nuluvius in forum New To JavaReplies: 3Last Post: 02-07-2008, 11:33 PM -
Function in a variable
By beserie in forum New To JavaReplies: 4Last Post: 01-07-2008, 03:12 AM -
I want to add function
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:25 AM -
function name
By osval in forum Advanced JavaReplies: 1Last Post: 08-06-2007, 08:56 PM -
Help with rebound function
By fernando in forum New To JavaReplies: 1Last Post: 08-06-2007, 07:12 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks