Results 1 to 6 of 6

Thread: Vector class and exceptions

  1. #1
    Join Date
    Dec 2009
    Posts
    211

    Vector class and exceptions

    Hello,
    I have defined this in my code:
    Code:
    Vector [] vc = new Vector [3], vc [0]. Add (0, "hello");
    It generates a java.lang.NullPointerException exception, though I defined the vector. How to eliminate that exception. If you have any more information on vector class and exceptions.Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    359

    Re: Vector class and exceptions

    Hello,
    I know what you're trying to do. An array of Vector, but I have never tired this before. You have null pointer because you create an array of vectors, but each element of your vector is not initialized.
    Code:
    Vector vc =new Vector();
    vc.add("hello");
    You can use the following and see if it works with the code.

  3. #3
    Join Date
    Dec 2009
    Posts
    263

    Re: Vector class and exceptions

    Hello,
    Even i had a similar kind of a problem but I did not found a solution for this, so, please help me with this. My goal is to build an array and each array element is an array of length dynamic example:
    elem0 ((), (ele1, ele2, ele3), (ele4, ele5)).
    I think of building a first vector length 3:
    Vector [] v = new Vector [3];
    then every time I set a 2 nd vector length n: Vector [] v2 = new Vector [n], I met the v2 and every time I assigns to v: v [i]. addElement (v2). Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Vector class and exceptions

    Hello,
    You can try the following code:
    Code:
    Vector vc =new Vector();
    Vector rw = new Vector();
    
    rw.addElement("hello");
    vc.addElement(rw);
    If you have any more quires regarding this then post back with it.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Vector class and exceptions

    Hello,
    Otherwise you can use arrays.
    Here is the code for that.
    Code:
    Object[][] t = new Object[3][];
    
    t[0][] = new Object[4];
    t[1][] = new Object[6];
    t[2][] = new Object[2];
    Because here you can put the size you want in each item in your array of size three. See if this works for you if yes then well and good and if no then we will suggest you a different solution for this, but first try this one.

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Vector class and exceptions

    Hello,
    Code:
    For each v [], you need to make a new Vector ()...
    well actually you have initialized your table but it must initialize after each item in this table
    In your example it gives:
    Code:
    Vector[] vc =new Vector [3];
    vc[0] = new Vector();
    vc[0].add(0,"hello");

Similar Threads

  1. Creating a vector type of a class
    By Xmen in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 03:38 AM
  2. What are Exceptions in PHP 5?
    By DANIEL 602 in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 01:35 AM
  3. Function problem with Vector Class
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 12:52 AM
  4. What is Log .NET Exceptions
    By Agneya in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 01:34 AM
  5. How to sort vector objects by class member variables in c++?
    By Linoo in forum Software Development
    Replies: 4
    Last Post: 29-01-2010, 07:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,829,862.31852 seconds with 16 queries