Re: ScalarType name already used ?

Alexandre Delarue wrote:
> I'm developing an application that needs to display several times the
> same data model, based on different imput files. This application
> creates a new instance of a class, let's call it VisADViewer, for each
> file. When the second instance of the class is created, the following
> exception is thrown:
> Visad.TypeException : ScalarType: name already used
> This happens in this section of my code:
> ...
> RealType xRT = new RealType("latitude", null, null);
> RealType yRT = new RealType("longitude", null, null);
> RealType zRT = new RealType("temperature", null, null);
> ...
> I have nothing declared static... in my code. Did anybody ever
> experience something like that ? Any idea to solve the problem ?
> (My first thought is that something may be declared static in the visad
> package...)

VisAD remembers all ScalarTypes (including RealTypes.)

The second time around, you'll want to fetch the original type.
Change the above code to something like this:

  RealType xRT;
  try {
    xRT = new RealType("latitude", null, null);
  } catch (TypeException te) {
    xRT = RealType.getRealTypeByName("latitude");

Even better might be to have a method like:

  private static RealType getReal(String name)
    try {
      return new RealType(name, null, null);
    } catch (TypeException te) {
      return RealType.getRealTypeByName(name);

and then your original code becomes:

  RealType xRT = getReal("latitude");
  RealType yRT = getReal("longitude");
  RealType zRT = getReal("temperature");

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