Results 1 to 3 of 3

Thread: Null pointer error in java

  1. #1
    CoxWatson is offline Senior Member
    Join Date
    Dec 2009
    Posts
    232
    Rep Power
    3

    Default Null pointer error in java

    This is my code
    Code:
    c1 { int h, double b}
    c2 { int lb double[] y, c1[][] x}
    class3{
    obj = new c2();
    obj.lb = Nb_int;
    obj.y = new double[nb_int];
    obj.x = new c1[nb_int][nb_int];
    }
    I get an error "null pointer", the error lies in assigning values to my obj.x, I think a pb of initialization, I'm gone the objects integrated in other objects. Any idea would be highly appreciated.
    Last edited by CoxWatson; 03-19-2010 at 01:34 PM.

  2. #2
    BellWard is offline Senior Member
    Join Date
    Dec 2009
    Posts
    236
    Rep Power
    3

    Default

    The init an array has more dimensions this fact in sequence Have a look at the following code. Hope this will help you.

    Code:

    Object t[][] = new Object[10][];
    for (int i = 0; i < 10; i + +)
    {
    t[i] = new Object[10];
    }
    Last edited by BellWard; 03-19-2010 at 01:39 PM.

  3. #3
    MorganCooper is offline Senior Member
    Join Date
    Dec 2009
    Posts
    233
    Rep Power
    3

    Default

    I have a code with me, please check if this helps

    Code:

    c1 { int h, double b}
    c2 { int lb double[] y, c1[][] a}
    class3{
    obj = new c2();
    obj.lb = Nb_int;
    obj.y = new double[nb];
    c1[][] a;
    a = new c1[size1][];
    for(int i = 0; I <a.length; I + +) {
    a[i] = new c1[size2];
    for(int j = 0J <a[i].lengthJ + +){
    a[i][j] = new c1(-1, -1);
    }
    }

Similar Threads

  1. Malformed error in java
    By CarterBaker in forum Programming
    Replies: 1
    Last Post: 07-10-2010, 01:08 PM
  2. Null Value in C#
    By HallMiller in forum Programming
    Replies: 2
    Last Post: 04-06-2010, 03:11 PM
  3. Java error in windows 7
    By Williamsjones in forum Windows 7/2000/NT
    Replies: 3
    Last Post: 03-30-2010, 02:24 PM
  4. Null modem
    By AdamsClark in forum General Internet Terms
    Replies: 1
    Last Post: 03-06-2010, 03:04 PM
  5. In Java Script how to Check Null Value?
    By CruzPowell in forum Programming
    Replies: 1
    Last Post: 02-11-2010, 05:15 PM

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
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48