Re: Jython question: RealTupleType throws TypeException(components must be non-null)


Thanks for explaining what's going on. This kind of thing probably wouldn't happen much in real life, since I'd know exactly what the units were. It's more likely to happen when you're trying out stuff and trying to figure out how it works, as I was.

I appreciate you guys being so responsive. Have a good weekend.


At 04:02 PM 6/21/2002, Curtis Rueden wrote:
Hi Frank & Tom,

Actually, this problem appears to be a quirk in VisAD,
demonstrated by the following code snippet:

import visad.*;
public class GetRealTypeTest {
  public static void main(String[] args) {
    System.out.println(RealType.getRealType("r1", SI.second));
    System.out.println(RealType.getRealType("r2", SI.meter));

This program outputs:

What this means is that getRealType returns null if you try to
obtain a RealType with a given unit, when that RealType already
exists without the proper unit.

Indeed, checking the source confirms this:

    RealType rt = getRealTypeByName(name);
    if (rt != null)
       * Ensure that the previously-created instance
       * conforms to the input arguments.
      if (!Unit.canConvert(u, rt.DefaultUnit))
        rt = null;

So, since the JPython editor doesn't run the code in a
separate JVM by default, the RealTypes created when executing
Frank's code remain in memory, and if you run the program
again with the "SI.meter.divide(SI.second)" part uncommented,
speed will be null because it doesn't have a convertible unit.

My advice is to settle on which units your RealTypes will use
so that this problem doesn't come up.  If you need to fiddle
with the units for testing, I suggest you either use the
editor's "Launch JPython in a separate process" option, or
else from the command line, test your script with:

       java visad.python.RunJPython


At 01:23 PM 6/21/2002, Tom Whittaker wrote:
> looks like there is some problem with the name "speed" related
>to the editor - have no ideas at this point, so I'll have to leave it to
>Curtis to comment on.
>On Fri, 21 Jun 2002, Frank Gibbons wrote:
>> from visad import *
>> from visad.python.JPythonMethods import *
>> from visad.java2d import DisplayImplJ2D
>> t = getRealType("time", SI.second)
>> h = getRealType("height", SI.meter)
>> speed = getRealType("speed")#, SI.meter.divide(SI.second))
>> h_s_tuple = RealTupleType(h, speed)
>> func_t_tuple = FunctionType(t, h_s_tuple)
>> throws:
>> Traceback (innermost last):
>>    File "C:\VisADJython\", line 11, in ?
>> visad.TypeException: TupleType: components must be non-null
>>          at visad.TupleType.<init>(
>>          at visad.RealTupleType.<init>(

PhD, Computational Biologist,
Harvard Medical School BCMP/SGM-322, 250 Longwood Ave, Boston MA 02115, USA.
Tel: 617-432-3555 Fax: 617-432-3557

  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: