Discussion Board
Go to the previous messageThere are no next messages
Current Forum: Homework 3 Forum
Date: Sun Sep 30 2001 2:36 pm
Author: Lao, William <wlao@andrew.cmu.edu>
Subject: Re: Compilation Error: static to nonstatic?

if you declare root inside the TrieNode class, by adding keyword 'static' in front of root(in your case TrieNode) you are essentially saying that there is only one instance of that object. so every new TrieNode you create will have a root that refers to the same thing. I'm not quite sure where you are going with the tn = root, if you are trying to add a new TrieNode to root it might be easier if you created root in the Parser constructor and made an insert call in your processDataFile() via " root.nameOfYourArray[(int)token.charAt(0)].InsertWord( token ) " (you also might want to modify token for nullpointerexceptions or also pass in the line number for the search() function) this will set up an recursive call if your insertWord() function is recursive ^.^

TrieNode tn;
tn = root;
^
Error message:
Can't make static reference to a nonstatic variable root.

//root is constructed as:
//TrieNode root = new TrieNode();
//which construct a TrieNode with an array of size 256, and nothing else

1. How should i fix this problem?
2. if i construct the root the way describe above, would my root == null?

thanx,
Helen
Post response

Go to the previous messageThere are no next messages
Current Thread Detail:
Compilation Error: static to nonstatic?      Han, Shanshan      Sun Sep 30 2001 1:42 pm       
Re: Compilation Error: static to no...      Lao, William      Sun Sep 30 2001 2:36 pm       

Back to previous screen