Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Null pointer error in java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 19-03-2010
Member
 
Join Date: Mar 2010
Posts: 197
Null pointer error in java
  

Hello,
This is my code
Code:
c1 { int h, double b}
c2 { int lb double[] y, c1[][] x}

class3{

myObject = new c2();

myObject.lb = Nb_int;
myObject.y = new double[nb_int];
myObject.x = new c1[nb_int][nb_int];
}
I get an error "null pointer", the error lies in assigning values to my myObject.x, I think a pb of initialization, I'm lost in the objects included in other objects. Any help regarding this will be appreciated. Thanks in advance.

Reply With Quote
  #2  
Old 19-03-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Null pointer error in java

Hello,
The init an array has more dimensions this fact sequentially
Have a look at the following code
Code:
    Object t[][] = new Object[10][];
    for (int i = 0; i < 10; i + +)
    {
      t[i] = new Object[10];
    }
Hope this will help you.
Reply With Quote
  #3  
Old 19-03-2010
Member
 
Join Date: Dec 2009
Posts: 202
Re: Null pointer error in java

Hello,
Even I am trying a similar kind of a program. I find it hard to understand. Your code will not create but initializes. Am I mistaken? I tired to assign values to myObject.x [0] [0]. MyObject.x a and [0] [0]. , I have the error "null pointer"? I have taken the reference of the above post as a example. If you have any other alternative for this then please let me know. Thanks in advance.
Reply With Quote
  #4  
Old 19-03-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Null pointer error in java

Hello,
The above code sets the table has 2 dims so it can receive Object (it was just an example, use the type that you agree) but do not fill with objects. So if you access the element array [0] [0] is null that obviously has you fill your table after its init. I hope you are getting the point what I am trying to explain here. If you need more information on this then you should turn to the core java for the basics.
Reply With Quote
  #5  
Old 19-03-2010
Member
 
Join Date: Nov 2009
Posts: 446
Re: Null pointer error in java

Hello,
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);
      }
}
Reply With Quote
  #6  
Old 19-03-2010
Member
 
Join Date: Mar 2010
Posts: 197
Re: Null pointer error in java

Hello,
Please check my updated code:
Code:
c1 { int h, double b}
c2 { int l double[] y, c1[][] a}

class3{

obj = new c2();

obj.l = 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].Index = -1;
      a[i][j].value = -1;
      }
}
/ / Finally, I must have:
obj.l = val; / / Successful
obj.y = aut; / / Successful
obj.a[i][j].h = une; / / Null pointer
obj.a[i][j].b = encr; / / Null pointer
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Null pointer error in java"
Thread Thread Starter Forum Replies Last Post
VMplayer: Using of shared folder in Fedora 16 gives Kernel null pointer at the time of booting He_Man Windows Software 3 04-02-2012 12:58 AM
Dereferencing NULL pointer in C++ TO-Phir Software Development 4 26-06-2011 07:42 PM
Nokia 6300 gives "Null Pointer" error message Nadiaa Portable Devices 4 08-02-2010 09:49 PM
Differentiation between void pointer and null pointer Ram Bharose Software Development 5 18-01-2010 11:11 AM
java error “javascript:void(null)” Kitaen Windows XP Support 3 27-07-2007 05:13 AM


All times are GMT +5.5. The time now is 05:36 AM.