main method question

I'm still reletively new to Java, so forgive if this question sounds stupid. But what I'm trying to do is open a text file, read it, create one linked list of all the tokens. then print out the list, of tokens words. I'm sure I have semantic, problems in my code but what I'm trying to do is figure out to link , the method that reads the filepublic void readInFromFile(String infilename) throws Exception to the main method, so I can test my code, and see what needs to be fixed. Here's the code below. The Node, class was graciously give to us by my proffesser so that part is all set.

The wordcount class is mine, and that's where the problem is.

publicclass Node{

publicint element;

public Node next;

/** Constructor

|

| "next" will become the successor to this new node

*/

public Node (int data, Node next )

{

element = data;

this.next = next;

}

/** return the data */

publicint getElement()

{

return element;

}

/** return the successor */

public Node getNext()

{

return next;

}

/** set the element of this node */

publicvoid setElement(int newData )

{

element = newData;

}

/** set the successor of this node */

publicvoid setNext( Node newNext )

{

next = newNext;

}

}

publicclass wordCount{

protectedstatic Node head;// head of the list

protectedlong size;// number of nodes in the list

/** Constructor -- create empty list */

public wordCount()

{

head =null;

size = 0;

}

/** addFirst -- insert a new node at the head */

publicvoid addFirst(int data )

{

Node nnode =new Node( data, head );

head = nnode;

size++;

}

publicvoid readInFromFile(String infilename)throws Exception

{

Scanner fileScan;// To scan each line of the file

try{// Attempt to open the file

fileScan =new Scanner(new File(infilename));

}catch (Exception e){// On any IO error, throw a CException

thrownew Exception("Can't read " + infilename);

}

Node p = head;

int lnum = 0;// The line number in the input file

while (fileScan.hasNext()){

while (p.next !=null)

p = p.next;

size ++;

lnum = lnum + 1;

String s = fileScan.nextLine();

StringTokenizer st =new StringTokenizer(s);

}

}

/** traverse -- print each node in order */

publicvoid traverse()

{

Node p = head;

while ( p !=null )

{

System.out.print( p.getElement() );

p = p.getNext();

if ( p !=null )

System.out.print(",");

}

System.out.println();

}

}

publicstaticvoid main ( String[] args )throws FileNotFoundException

{

wordCount myList =new wordCount();

Node p;

}

}

[6253 byte] By [JimmyElvisa] at [2007-10-2 7:04:48]
# 1
I did not understand your problem at all.
Catscratch1a at 2007-7-16 20:35:47 > top of Java-index,Java Essentials,New To Java...
# 2
@OP.What does the stack trace say? What kind of exception do you get?I would also like to know why head is declared to be static.Kaj
kajbja at 2007-7-16 20:35:47 > top of Java-index,Java Essentials,New To Java...
# 3
Are you saying you want to force an exception to be thrown so you can test error handling. Or are you saying it DOES throw an exception, or what?
Dick_Adamsa at 2007-7-16 20:35:47 > top of Java-index,Java Essentials,New To Java...