473,671 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

object instantiation question

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


Jul 17 '05 #1
3 5216
"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.
Jul 17 '05 #2
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*****@avoidi ng.spam> wrote in message
news:Xn******** *************** *****@138.126.2 54.210...
"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.

Jul 17 '05 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1687
by: johny smith | last post by:
Based on my experience there is two ways to instantiate an object. Method 1: Car* car1 = new Car();
2
2241
by: Haro Panosyan | last post by:
Suppose I have defined a templete function prototype in a header file and the body in .cpp file and created executable without actually calling the templete function. Now let say from that executable I am loading a shared object and executing(dlsym-ing) some f() function, which inside calls the templete function. (Of course the header file with templete prototype is included in shared object source file, so it could be compiled.)
6
22515
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was 'myDog' without having to pass it as a parameter. //////////////////////////////// function...
12
2613
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in an embedded environment with multiple processors. I created a policy for classes, which, I had hoped, would automatically register the class with the appropriate factory: // In some header file... #include <cassert>
11
3818
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of ways to do this through prototyping and other techniques, but these behaviors need to be static and...
26
5670
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized several parts of the DOM, but this does not include the window object. Thank you
7
2449
by: John A Grandy | last post by:
I'm trying to get a decent idea of the relative performance of three types of implementations of data-access classes in ASP.NET 2.0. I believe this boils down to a more basic question regarding the cost of object instantiation in .NET 2.0. It becomes especially relevant to web-app data-access classes due to the vast variety of db queries page requests may require. Caching is not appropriate for most of these datasets, and so many...
8
2231
by: v4vijayakumar | last post by:
Is there any way to defer instantiation of " t1" to the constructor of "test1"? because, "t1" can only meaningfully initialized in the "test1" constructor. #cat test.cpp #include <iostream> using namespace std; class test {
36
3830
by: zouyongbin | last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this should not appear in a header file: int ix; The inclusion of any of these definitions in two or more files of the same program will result in a linker error complaining about multiple definitions. So this kind of definition should be avoided as much as possible. But as we know, the definition of a class is always in a header file. And we can use "#ifndef" to eliminate...
2
1872
by: WittyGuy | last post by:
Hi My class looks something like this: class Base { public: Base () {} ~Base () {} // No virtual dtor in the base class private: };
0
8390
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8909
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8596
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4399
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.