Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Bravi kumar

Greenhorn
+ Follow
since May 03, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bravi kumar

Hi,

I am facing the null pointer exception since many days.

Could anybody please help me how to fix the above null pointer exception ?

I am copying the error trace from eclipse console window.

Caused by: java.lang.NullPointerException
at java.util.Hashtable.get(Hashtable.java:334)
at ....tools.hmi.window.OdWinTreeChooser.setHierarchyToObject(OdWinTreeChooser.java:497)



Thanks for helping.

Regards,
Kumar.


5 years ago
Hello Raghava,

Yes i am sure about creating new vector object for every loop runs.

Difference between creating objects inside for loops and outside for loops

Inside for loop

for(...;..;..){
Vector v=new Vector();
v.add(any object);
}

In the above code for every loop runs a new Vector object is created so that we can't see previously created object as it was already cleaned by garbage collector.

Outside for loop.

Vector v=new Vector();
for(...;..;..){
v.add(any object);
}

In the above code, we are creating only one vector object and adding millons of objects to it causes to some what error like outofmemoryerror.. Here we are not allowing GC to clean objects which are no longer used.

Creating objects inside or outside depends on the situation.

furthermore whatever i coded earlier might be correct. i can't explain the intention as it was developed by some other developer and i am maintaining the project.


Thanks & Regards,
Ravi Kumar. B


6 years ago

Stephan van Hulst wrote:You are probably allocating a lot of objects in a long (possibly infinite) loop, or you have a memory leak somewhere (e.g. storing object references in a list and forgetting to null them out when you're done with them).



Hi,

i am also getting outofmemoryerror :java heap space

can you please help me out in fixing this error.

code:

public static Vector multiplyVectors(Vector vect1,Vector vect2){

Vector resultVector=new Vector();
for(int i=0;i<vect1.size();i++){
for(int j=0;j<vect2.size();j++){

vector v=new Vector();

v.addAll((Vector)vect1.elementAt(i));
v.addAll((Vector)vect2.elementAt(j));

resultVect.add(v);

}
}
}

in the above program, both vector sizes reaches to more than 5000 causes outofmemoryerror.


Thanks for help in advance.>
6 years ago