"Kavindra Malik" <ka************ @hotmail.com> wrote in
news:uA******** *******@fe2.col umbus.rr.com:
I am learning to use a shareware package for statistics and
optimization- drasys.or.* ( found at http://opsresearch.com/OR-Objects/)
to get to use some stats and operations research objects. Among other
things, this package has classes VectorI (and MatrixI) and I am having
difficulty instantiating variables of these classes.
I begin with declaration:
VectorI D = null;
If I try a method on D - called setElementAt, which sets a given element
to a given value:
D.setElementAt( row_id, val);
I get a java.lang.NullP ointerException .
It seems like (and I think) D needs to be initiated. However, I have
tried each of the following (even desperate) attempts to instantiate it:
D = new VectorI(); - Error: Can not instantiate the type
VectorI,
as it is not a concrete class
D = new VectorI(20); - Error: Same as above
D = new VectorI[20]; - Error: Change type of D to VectorI[]
I am new to Java - so might be making some fundamental error. But, after
banging my head against this simple issue - I am in need for some help
and would be much obliged for all suggestions.
Thanks,
kavindra malik
Looking at the API index at
http://opsresearch.com/OR-Objects/ap...x-all.html#_V_
I see that VectorI is an interface, not a class. This means that you
cannot create VectorI objects. You can create objects of some other class
that implements VectorI.
Looking at the api documentation for VectorI at
http://opsresearch.com/OR-Objects/ap...x/VectorI.html
reveals that objects of class Vect implement the VectorI interface.
Reviewing the documentation for Vect (by following the link) reveals that
Vect is abstract, so you can't create Vect objects either. However,
1) Vect implements VectorI (good!)
2) ContiguousVecto r and SparseVector are subclasses of Vect.
Following the link to ContiguousVecto r reveals that this is a concrete (not
abstract) public (accessable by you) class (can be instantiated, not just
an interface, and providing the VectorI interface).
Thus, you can do this:
D = new ContiguousVecto r();
or use any of the other six constructors. You will then be able to use any
method of VectorI on the resulting ContiguousVecto r, such as setElementAt.
This form of documentation is common in Java. It is known as Javadocs.
The Javadocs are your friend! Use them! If you haven't already, go to
http://opsresearch.com/OR-Objects/download/free.html
read the section "Documentat ion Installation" and follow the instructions
(both of them!).
Another hint: It is not required, but the coding style in Java is that
class names start with an uppercase letter, variables start with a
lowercase letter. Your variable named "D" would be better named "d", or
something more descriptive, like "data" or "modelData" or "populationData "
or ...
Good Luck!
--
Ian Shef
These are my personal opinions and not those of my employer.