|
Greg...
|
Posted: Aug 20, 2003 6:08 AM
|
|
And to all the others who are willing to post opinion... So here is the program again this time I don*t think that it is too messy...
import java.util.*;
/** *This class will make the hash table.The key that the hash table uses will be *the sourceID of the relation.And the value will be a vector which consists of *the relations that have the same sourceID as the so given relation. *the program gives a nullpointer exception.(...) * @author tusheva */ public class AnnotationThread { private Vector v; private Hashtable hashtable; /** Creates a new instance of AnnotationThread *Just to mention that Relation is interface that is *implemented by the class Analogy so that when I call *the makeHashtable() methos in main I call it with an *instance of Analogy that implements Relation so *that is not a problem I hope.. */
public AnnotationThread(Relation r) { Vector v = new Vector(); Hashtable hashtable = new Hashtable(); } public Hashtable createHashtable(Relation r){ String key1 = r.getSourceID(); if (v.isEmpty()) { v.add(r); hashtable.put(key1,v); } else { Vector v1=(Vector) hashtable.get(key1); v.add(v1); hashtable.put(key1, v); } return hashtable; } public static void main (String args[]){ Analogy a = new Analogy(0.1f,0.2f,"a","b"); AnnotationThread example = new AnnotationThread(a); System.out.println(example.createHashtable(a)); } }
And maybe it will be useful to attach the Analogy class...
/** *One of the structure relations named Analogy. * @author tusheva */ public class Analogy implements Relation { /**The fields of the instances of the class Analogy*/ private float sourceWeight; private float destinationWeight; private static final String RELATIONTYPE = "Analogy"; private String sourceID; private String destinationID; /** Creates a new instance of Analogy*/ public Analogy(float sourceWeight, float destinationWeight,String sourceID,String destinationID) { this.sourceWeight = sourceWeight; this.destinationWeight = destinationWeight; this.sourceID=sourceID; this.destinationID=destinationID; all.add(this); } /** * Calculates the weight for the source and destination node (according to * its relation type) * @return the weight */ public float calculateWeight(){ float weight; weight=this.sourceWeight+this.destinationWeight-this.sourceWeight*this.destinat ionWeight; return weight; } /** * Sets the source weight. * @param sourceWeight the source weight */ public void setSourceWeight(float sourceWeight) { this.sourceWeight = sourceWeight; } /** * Sets the destination weight. * @param destinationWeight the destination weight */ public void setDestinationWeight(float destinationWeight) { this.destinationWeight = destinationWeight; } /** * Gets the source weight. */ public float getSourceWeight() { return this.sourceWeight; } /** * Gets the destination weight. */ public float getDestinationWeight() { return this.destinationWeight; } /** * Gets the relationstype. */ public String getRelationType() { return this.RELATIONTYPE; } public void setSourceID(String sourceID) { this.sourceID=sourceID; } public void setDestinationID(String destinationID) { this.destinationID=destinationID; } public String getSourceID(){ return this.sourceID; } public String getDestinationID(){ return this.destinationID; } }
And still I do get this exception ... I mean the nullpointer exception ... After all I do initialise v and hashtable in the constructor... Does this mean that they are not visible for creteHashtable() .. I will really appreciate an answer Cheers
|
|