SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-08-2005, 10:55 AM
davin's Avatar
davin davin is offline
Sage Advanced User
 
Join Date: Jan 2005
Location: El Segundo, CA
Posts: 138
Calling custom java classes from studio

I need to use a custom java class to do COM interfacing. I've got the class written and it works if I write a standalone java app and run it at the command line. But I'm having problems getting it to work in studio.

Here's what happens... under an Item widget inside a menu, I have an Action that evaluates a "new" expression and sets a variable. I then try to call a method inside that class using the variable reference. I always get a null pointer exception. If I use the evaluation tool to evaluate the new command it returns a value, but the variable that I want to set to that value does not persist.

Here's an example. I have Foo.jar in the sagetv/JARs directory.

Action widget: obj = new_Foo_Bar()
Action widget: Foo_Bar_fubar(obj)

The first statement evaluates fine, but the second one give a null pointer exception.

On the other hand, the following works:

Action widget: Foo_Bar_fubar(new_Foo_Bar())

Any ideas? Why isn't the obj variable getting set? I want it to persist so that I can use it in future widgets. I am a java newbie, so thanks in advance for being gentle. I figure I'm making some sort of newb mistake.
Reply With Quote
  #2  
Old 11-08-2005, 11:07 AM
Crashless's Avatar
Crashless Crashless is offline
Sage Icon
 
Join Date: Oct 2003
Location: Los Angeles, CA
Posts: 1,224
Probably not a Java issue - do you have a variable widget named 'obj' in a parent widget to whereever you want to use it?

Studio has nested variables, so a variable set in one tree is only accessible down the line, not back up it.

In order to make a variable accesible to all trees, you should put a variable widget (the blue arrow up) at the menu level with value 'null', then any time you set it, all parts of the menu will be able to access it.
__________________
Give the Meekell STV a try!
Reply With Quote
  #3  
Old 11-08-2005, 11:10 AM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,595
I'll leave the java comments to someone else for now, but since "Foo_Bar_fubar(new_Foo_Bar())" is working, it sounds like it may just be a variable scope issue. (See p. 45 of the Studio manual for info on that.)

Make sure the use of the 'obj' variable after it is initialized is in a child tree of where it was set, or place an attribute widget that declares the 'obj' variable at a higher point in the tree that is a shared parent of any place you are trying to use 'obj' in a menu.

To simplify remote Studio debugging, you might want to post a screen shot of the section of code where those lines are contained.

- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #4  
Old 11-08-2005, 11:12 AM
nielm's Avatar
nielm nielm is offline
SageTVaholic
 
Join Date: Oct 2003
Location: Belgium
Posts: 4,496
It probably is getting set, but it is probably going out of scope before you are using it.

As you are usign implicit variables, check the docs on scope... the second action must both be children of the same widget for the second to see the implicit variable 'obj' which is defined in the first...

Secondly how persistant do you want your object?
  • just while executing this widget tree -- use the implicit variable.
  • only while this menu screen is shown -- use an 'attribute' widget to store the return of the 'new_Foo_Bar()'
  • for this and the next menu screen -- use 'AddStaticContext("obj",obj) after you have called your 'new_Foo_Bar()'
  • for the lifetime of the Sage process -- use 'AddGlobalContext("obj",obj)
Examples of persistant java objects are in my rss newsreader, imdb search and dynamic menu imports
__________________
Check out my enhancements for Sage in the Sage Customisations and Sageplugins Wiki
Reply With Quote
  #5  
Old 11-08-2005, 11:14 AM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,595
Quote:
Originally Posted by Crashless
variable widget (the blue arrow up)
Oh... is that what it is? I always thought it was an upside-down heart!

Edit: I guess everyone thinks it is a variable usage issue.

- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #6  
Old 11-08-2005, 11:19 AM
Crashless's Avatar
Crashless Crashless is offline
Sage Icon
 
Join Date: Oct 2003
Location: Los Angeles, CA
Posts: 1,224
"scope" !

That's the word I couldn't think of.

Quote:
Originally Posted by Opus4
Oh... is that what it is? I always thought it was an upside-down heart!
Come on Opus, everyone knows a heart would be red, not blue.
Reply With Quote
  #7  
Old 11-08-2005, 11:31 AM
stanger89's Avatar
stanger89 stanger89 is offline
SageTVaholic
 
Join Date: May 2003
Location: Marion, IA
Posts: 15,186
Not trying to promote my own stuff (as I'm far from a Java master), but check out the DVDPro2Sage stuff in either Meekell or SageMC 169, should give you an idea of how to deal with external Java classes.
Reply With Quote
  #8  
Old 11-08-2005, 08:01 PM
Narflex's Avatar
Narflex Narflex is offline
Sage
 
Join Date: Feb 2003
Location: Redondo Beach, CA
Posts: 6,313
I'm guessing the problem is that he put both Action Widgets underneath the Item Widget so that its only executing the second one and not executing the chain.

You should make "obj = new_Foo_Bar()" a child of the Item Widget and then make "Foo_Bar_fubar(obj)" a child of "obj = new_Foo_Bar()"
__________________
Jeffrey Kardatzke
Google
Founder of SageTV
Reply With Quote
  #9  
Old 11-09-2005, 12:37 AM
davin's Avatar
davin davin is offline
Sage Advanced User
 
Join Date: Jan 2005
Location: El Segundo, CA
Posts: 138
Thanks for all the input, folks. It was indeed a scoping issue. I added an attribute widget to the menu and all was well!!!
Reply With Quote
  #10  
Old 11-09-2005, 11:50 AM
Crashless's Avatar
Crashless Crashless is offline
Sage Icon
 
Join Date: Oct 2003
Location: Los Angeles, CA
Posts: 1,224
Quote:
Originally Posted by davin
Thanks for all the input, folks. It was indeed a scoping issue. I added an attribute widget to the menu and all was well!!!
I win!

well, tie, but I was first.
__________________
Give the Meekell STV a try!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.