|
| ||||||||||
| Tags: java, memory access, null pointer, pointer, programming language, value of address |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Null pointer error in java
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];
} |
|
#2
| |||
| |||
| 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];
} |
|
#3
| |||
| |||
| 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. |
|
#4
| |||
| |||
| 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. |
|
#5
| |||
| |||
| 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);
}
} |
|
#6
| |||
| |||
| 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 |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |