aspose file tools*
The moose likes Beginning Java and the fly likes constant error problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "constant error problem" Watch "constant error problem" New topic
Author

constant error problem

Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
hi eall,
im writing code for a server at the moment but cannot get past this sticky error, i duno how to do it. Any help is much appreciated:
error = cannot find symbol
variable topics

code =
public void getBlock(String id, BufferedReader in, PrintWriter out)
throws NoSuchTopicException, ServerException
{
int topicID = 0; // this will be set to the identifier of the topic
int blockNo = 0; // this will be set to the number of the requested block
// set the topic identifier: this will be the remainder (minus prefix)
// of the String id:
try
{
topicID = Integer.parseInt(id.substring(1));
}
catch (NumberFormatException nfe)
{
throw new NoSuchTopicException(NETWORK_FAULT);
}
// set the requested block number from client;
// should really check that the given line isn't empty!
String blockNoStr = in.readLine().substring(1);

try
{
blockNo = Integer.parseInt(blockNoStr);
}
catch (NumberFormatException nfe)
{
throw new ServerException(NETWORK_FAULT);
}

if (! topics.isIn(topicID))
{
throw new ServerException(NO_SUCH_TOPIC);
}
etc.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11311
    
  16

on this line:

if (! topics.isIn(topicID))

you are trying to use a variable called "topics" that has never been declared. where did it come from?

also, if you could use the code tags, your formatting would be preserved, and make your code easier to read. just use those "instant UBB code" buttons down below, and paste your formatted code between the two. or just hand generate them, without the space:

[ code]
//your code goes here
[ /code]


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
hey fred,
it was given to me in code that i was given to help me get started, the getTopic method was given.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11311
    
  16

is there more code you were given? this simply won't work - you can't use a variable that isn't defined anywhere. it looks like there should be some code somewhere else that creates the topics object... but i couldn't tell you what that code should be.
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
thanks fred, but no , we were just given the tasks that we needed to do and that piece of code that was included in order to "help us out" as yet tho, it seems only to be a hindrance
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
sorry, checked back on the website and it said the following underneath the given code:
Note that this assumes that topics is the name of the field storing the list of current topics, and that the constants from MBServerProtocolConstants are in scope (this can be achieved by declaring the class to implement that interface). This method takes a BufferedReader and a PrintWriter as parameters; the actual parameters given when this method is called should be a BufferedReader instance and a PrintWriter instance that have the input and output streams of the Socket connection to the client. The first parameter to the method should be the first line of input read from the client when a block of messages is requested (recall from the protocol described above that a block of messages is requested by the client sending a line with prefix '2' followed by the identifier of the topic). This implementation also assumes that messages and topics are stored in files on the file-store, in a directory called "Topics", which has a subdirectory for each topic, which in turn has files for each block of messages.

duno if this helps to clear it up any but hopefully it will, i still dont have a clue tho
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: constant error problem