Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 37

Thread: Getting information from API Class into main body....

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Getting information from API Class into main body....

    Hi,

    I'm new to JAVA and busy working with an API and I've hit a brick wall. What I want to do is extract information from an extended API class into the main body of the program. So, the extended class looks like this:

     
    class Ticker extends FXRateEvent
    		{
    			// No key set and no match implemented; this event matches all RateEventInfos
     
    			public void handle(FXEventInfo EI, FXEventManager EM)
    			{
    				//Just print the tick
    				FXRateEventInfo REI = (FXRateEventInfo) EI;
    				System.out.println(REI.getTick()+ ":"+ REI.getTimestamp());
    //				FXPair changedPair = REI.getPair();
    //				System.out.println(changedPair);
     
    			}
     
    		}

    Now I can call the class like so and it prints all the information:

                    Ticker ticker = new Ticker();
    		try { fxgame.getRateTable().getEventManager().add(ticker); }
    		catch (SessionException e) { fxgame.logout(); System.exit(1); }

    The problem is it's the class that doing the printing. In particular I am after the information in the line: FXPair changedPair = REI.getPair();

    I want to use that information in the Main body of the code. Can anyone tell me how to get that out of the class? I know I'm supposed to do a method and then call it, but all my attempts so far have failed.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    Save the reference(ticker??) to the class (Ticker) whose methods you want to call and use it to call the class's methods to get data from it.
    data = ticker.getData();

    The method getData() would be defined in the Ticker class.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    Can you show me that in code please? Where exactly do I save the reference ticker ? As far as I know I've already saved the data as : FXPair changedPair = REI.getPair();

    Now I need to call:

    ticker.changedPair();

    Or so I thought, but it fails.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    ticker is the variable that does the saving of the reference to a Ticker object.
    Define ticker at the class level so any methods can use it to reference the Ticker object.
    Note: a variable can be defined in one place and assigned a value in another place. Those two steps don't need to be on one line.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    So I need to create a new class ticker to extend the Ticker class ?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    I'm not sure I understand what you are asking.
    I was using values from the code you posted:
    Ticker ticker = new Ticker();
    ticker is a variable that has a reference to an instance of the Ticker class.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    Yes, so I created a new Object ticker from Ticker and then I do this:

    try { fxgame.getRateTable().getEventManager().add(ticker); }
    		catch (SessionException e) { fxgame.logout(); System.exit(1); }

    At this point the ticker object jumps into action and prints all the information as specified in Ticker. But I don't want to print it. I want to use the value of :

    FXPair changedPair = REI.getPair();

    I need to get that value out of the ticker object. It's encapsulated in there, so I can't access it.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    Can you make a small, complete program that compiles, executes and shows the problem? Your short code sections don't show the problem enough to understand it
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    Basically I want to do is:

    String pairTocompare = ticker.changedPair();

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    Ok, that looks like good code. What is the problem?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    That is the program at this point. I extend one event manager and print the values it gives.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    What is the problem then?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    It doesn't work. To do that changedPair needs to be a method. All my attempts at making it a method and then calling it has failed. The original Class is a void class and I'm looking for a return value.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    Can you make a small, complete program that compiles, executes and shows the problem? Your short code sections don't show the problem enough to understand it
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    Man, sadly I'd need to add passwords and account numbers to do that, as this information is called over via API. Be like giving you access to my bank account.

    Not only that, I'd have to give you the entire API which I have signed an agreement to not do. So it's not possible really.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    Don't post your current code, make a special smaller version that only shows the problem, nothing more is needed and will only confuse the issue.

    What is "API"? I use those letters for Application Program Interface.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    That's correct. This is a Program Interface. Look, as far as I know the solution should be something like this:

     
    		class Ticker extends FXRateEvent
    		{
    			// No key set and no match implemented; this event matches all RateEventInfos
     
    			public void handle(FXEventInfo EI, FXEventManager EM)
    			{
    				//Just print the tick
    				FXRateEventInfo REI = (FXRateEventInfo) EI;
    				System.out.println(REI.getTick()+ ":"+ REI.getTimestamp());
    //				FXPair changedPair = REI.getPair();
    //				System.out.println(changedPair);
     
    			}
     
    			public FXPair changedPair()
                            {
    				FXPair changedPair = REI.getPair();	
    			}
     
    		}
     
    		//all rate events
     
    		Ticker ticker = new Ticker().changedPair();

    But that fails...

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    that fails...
    Please explain.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    The compiler has several problems with it.

    First it doesn't recognise REI. Then it doesn't like the type of the object.

    Screen Shot 2014-05-22 at 9.13.44 AM.jpg

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    Please copy the full text of any error messages and paste it here. Not an image.

    doesn't recognise REI
    Where is REI defined?
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    This also fails:

    class Ticker extends FXRateEvent
    		{
    			// No key set and no match implemented; this event matches all RateEventInfos
     
    			public void handle(FXEventInfo EI, FXEventManager EM)
    			{
    				//Just print the tick
    				FXRateEventInfo REI = (FXRateEventInfo) EI;
    				System.out.println(REI.getTick()+ ":"+ REI.getTimestamp());
    //				FXPair changedPair = REI.getPair();
    //				System.out.println(changedPair);
     
    			}
     
    			public FXPair changedPair()
    			{
    				FXPair changedPair = REI.getPair();	
    				return changedPair;
    			}
     
    		}
     
    		//all rate events
     
    		FXPair alpha = ticker.changedPair();

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    This is getting to be a waste of time. You need to post the full text of the error messages.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    In the class FXRateEvent which is from the API and extended as ticker, point is I used it 3 lines before succesfully and it's still in the same class.

    --- Update ---

    1. REI cannot be resolved.
    2. Ticker cannot be resolved.

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Getting information from API Class into main body....

    Can you make a small, complete program that compiles, executes and shows the problem? Your short code sections don't show the problem enough to understand it.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Junior Member
    Join Date
    May 2014
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Getting information from API Class into main body....

    Thanks for the attempt to help Norm. Unfortunately I can't. As I pointed out you'd need the API. I can't give it to you. I've taken enough of your time already.

    Thanks again.

Page 1 of 2 12 LastLast

Similar Threads

  1. information on main method
    By antoni in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 10th, 2013, 10:30 PM
  2. Body Systems Class
    By lah2015 in forum Object Oriented Programming
    Replies: 2
    Last Post: September 16th, 2013, 11:44 PM
  3. Replies: 2
    Last Post: November 18th, 2012, 02:09 PM
  4. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  5. Having trouble printing object information in main class
    By KingLane in forum Object Oriented Programming
    Replies: 1
    Last Post: October 11th, 2009, 06:53 PM