By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,738 Members | 2,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,738 IT Pros & Developers. It's quick & easy.

object instantiation question

P: n/a
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.NullPointerException.

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


Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Kavindra Malik" <ka************@hotmail.com> wrote in
news:uA***************@fe2.columbus.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.NullPointerException.

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) ContiguousVector and SparseVector are subclasses of Vect.

Following the link to ContiguousVector 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 ContiguousVector();

or use any of the other six constructors. You will then be able to use any
method of VectorI on the resulting ContiguousVector, 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 "Documentation 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.
Jul 17 '05 #2

P: n/a
This was extemely helpful. I now know how to read the docs better (or at
all!) - and avoid posting unnecessary questions. Thanks a ton!

kavindra
"Ian Shef" <in*****@avoiding.spam> wrote in message
news:Xn****************************@138.126.254.21 0...
"Kavindra Malik" <ka************@hotmail.com> wrote in
news:uA***************@fe2.columbus.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.NullPointerException.

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) ContiguousVector and SparseVector are subclasses of Vect.

Following the link to ContiguousVector 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 ContiguousVector();

or use any of the other six constructors. You will then be able to use any method of VectorI on the resulting ContiguousVector, 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 "Documentation 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.

Jul 17 '05 #3

P: n/a
Make sure that the VectorI class is an instantiatable class, meaning its not
an interface or an abstract class. If so, then there might be an error in
the constructor of the class VectorI
- Hari
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.