SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

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 03-23-2006, 10:34 AM
aperry's Avatar
aperry aperry is offline
Sage Expert
 
Join Date: Jan 2005
Posts: 680
Accessing JAR's From Within Sage

I'm having a problem in Sage accessing JAR information. If I had the following code:
Code:
public class MyClass {
  private String myName;

  public MyClass(String name) {
    myName = name;
  }

  public String GetMyName() {
    return myName;
  }

  public void SetMyName(String name) {
    myName = name;
  }
}
I compile it up, put it into a JAR, and copy that JAR to the main JAR folder in the SageTV folder. If I take a variable I have defined, and do this:

myVar = new_MyClass("Fred")

It seems to create a valid variable (if I turn on the tracer, it shows a value of MyClass:xxxxx for myVar).

According to the Studio documentation, I should be able to do the following in a statement to get the current name from the above class.

MyClass_GetMyName(myVar)

However, when I do that, I get an error (I can get you the specifics if necessary).

I have tried various variations to get it to work, but to no avail. This class works fine with a test "main" java program I threw together.

Any ideas on what I might be doing wrong?

Last edited by aperry; 03-24-2006 at 01:29 AM.
Reply With Quote
  #2  
Old 03-23-2006, 10:55 AM
dflachbart dflachbart is offline
SageTVaholic
 
Join Date: Jan 2006
Location: Brookfield, CT
Posts: 2,743
Not sure about this, but try to put the class into a package ...

Dirk
Reply With Quote
  #3  
Old 03-23-2006, 12:43 PM
nielm's Avatar
nielm nielm is offline
SageTVaholic
 
Join Date: Oct 2003
Location: Belgium
Posts: 4,496
Packages are not required, but help to avoid namespace collisions...

errors / console output would be useful
Also turn on the error reporting in Studio..

One small point: you need to restart Sage to recognise new/updated JARs
__________________
Check out my enhancements for Sage in the Sage Customisations and Sageplugins Wiki
Reply With Quote
  #4  
Old 03-23-2006, 01:17 PM
aperry's Avatar
aperry aperry is offline
Sage Expert
 
Join Date: Jan 2005
Posts: 680
Quote:
Originally Posted by nielm
Packages are not required, but help to avoid namespace collisions...

errors / console output would be useful
Also turn on the error reporting in Studio..

One small point: you need to restart Sage to recognise new/updated JARs
I had been thinking about the package thing, and will probably do that, even though it may not be required. Note that the example I gave is a very simplified subset of what my overall package does.

Regarding the restarting, I have already restarted, Sage does not complain when I do the "new" statement.

I already have error reporting turned on, so when I get a chance this evening, I'll report back the error I am seeing (seems to me I remember seeing something like "reflection error", or perhaps I'm just thinking of what I saw when I looked in my mirror this morning...) . Anyhow, I'll let you know.

Last edited by aperry; 03-23-2006 at 01:19 PM.
Reply With Quote
  #5  
Old 03-23-2006, 04:11 PM
davin's Avatar
davin davin is offline
Sage Advanced User
 
Join Date: Jan 2005
Location: El Segundo, CA
Posts: 138
Did you declare myVar in studio before the new statement? I had a similar problem... the new worked just fine, but the variable that it was set to did not persist, so when I went to use it, Studio didn't know what it was.

Here's the thread which resolved my problem: http://forums.freytechnologies.com/f...ad.php?t=13962
Reply With Quote
  #6  
Old 03-23-2006, 05:08 PM
aperry's Avatar
aperry aperry is offline
Sage Expert
 
Join Date: Jan 2005
Posts: 680
The variable is actually being set up as a global as I need it in other menus, so it has been defined. It should be okay I think...
Reply With Quote
  #7  
Old 03-24-2006, 04:50 AM
nielm's Avatar
nielm nielm is offline
SageTVaholic
 
Join Date: Oct 2003
Location: Belgium
Posts: 4,496
"reflection error" sounds about right -- any errors from Java will trigger these, but the original error and possibly a stack trace will be reported in the logging -- if you have it enabled -- and in the troubleshooting console -- if you have it enabled

The fact that it is a reflection error suggests that your java is being called, which is a good sign, and in such a trivial class, it will probably be caused by a NullPointerException -- myVar is null..
__________________
Check out my enhancements for Sage in the Sage Customisations and Sageplugins Wiki
Reply With Quote
  #8  
Old 03-24-2006, 07:33 AM
aperry's Avatar
aperry aperry is offline
Sage Expert
 
Join Date: Jan 2005
Posts: 680
Well, I got it fixed. The class I put in the original message was just an example of what I was trying to do, the real one is a bit more complicated.

Anyhow, what happened was in the real class, I was trying to instantiate an object using the SelectedPath variable from a popup file browser selection. I figured out that SelectedPath was not a String like I originally though, rather it was a java.io.File object. I added this to my code:

myFilename = java_io_File_toString(SelectedPath)

Then, I used myFilename rather than SelectedPath in my code, and it all started working fine.

Thanks for the pointers all, it did get me looking in the right place. The error popup did not specifically point this out, it just said that I couldn't instantiate my class. I kept trying to look at what SelectedPath was, and it was showing me the text, so I kept assuming that SelectedPath was a string. Once I figured out it was not, that solved my problem.

Thanks again!
Reply With Quote
Reply


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

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:31 AM.


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