Extends Error

A

andrewzzz

Hi guys,
I have a class("myplatform") which extends another("platform"). From a
main class I instanciate "myagent" but when I try to use any of the
methods inside Platform (the superclass of the class I just
instanciated) , I get a nullpointer error.
I checked the code many times and if I call the method directly from
the superclass it works correctly, (but I shouldn't do that really).
Somebody know why?
Here is simplified code of "platform" :

-----------------------------------------------------------------------------------------------------------------------------------------
package agentsLibrary;
public class Platform {
private String listaserver;
private static PathEl[] vettoreservers=null;

public Platform(String listaserver){
this.listaserver=listaserver;
//vettoreservers is then retrieved from an xml, I checked and is
correct!
}

synchronized public static PathEl[] getRemainingServers(){
return vettoreservers;
}

//...and other get methods like that...
}
-------------------------------------------------------------------------------------------------------------------------------------------

and code of MyPlatform (the subclass)

package test;
import agentsLibrary.Platform;


public class MyPlatform extends Platform{

private HashMap prodmap=null;
private ProductType pt=null;
private String nomefile;

public MyPlatform(String listaserver) {
super(listaserver);
this.prodmap=new HashMap();
nomefile="prodotti.xml";

}


public synchronized void loadInfo() {

//loads some info


}

synchronized public HashMap getProductsMap(){
return prodmap;
}

}


----------------------------------------------------------------

A main class creates an instance of myplatform , then tries to call
"synchronized public static PathEl[] getRemainingServers()" (PathEl[]
dpath=platf.getRemainingServers();) from the superclass "Platform",
but get nullpointer!!
(note that if I check the content in platform and myplatform is correct
and not null!!!)


Thanks a lot javaboys!
 
O

Oliver Wong

andrewzzz said:
Hi guys,
I have a class("myplatform") which extends another("platform"). From a
main class I instanciate "myagent" but when I try to use any of the
methods inside Platform (the superclass of the class I just
instanciated) , I get a nullpointer error.
I checked the code many times and if I call the method directly from
the superclass it works correctly, (but I shouldn't do that really).
Somebody know why?
Here is simplified code of "platform" :
[snip "simplified" code]

Rather than posting some paraphrased pseudocode, could you post an SSCCE
that demonstrates the problem? http://mindprod.com/jgloss/sscce.html

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top