variable might not have been initialized!!
I keep getting this error message with this code and I don't understand what it's telling me! Do I need to sort of merge the two chatter methods?
Code java:
.\Chatter.java:96: error: variable name might not have been initialized
}
^
1 error
And that is the whole error. it points towards the } which is closing the final method (public Chatter).
I would really appreciate if someone could help me with this, I also get the feeling that I will need to change a method in another class which uses this one once this problem has been resolved..
The Code
Code java:
public class Chatter implements Runnable
{
/**
* The name of the Chatter.
* This should be the ID chosen by the remote user on joining
* the chatroom.
* This value is set in the constructor.
*
*/
public final String name;
public void run()
{
}
/**
* Creates a new <code>Chatter</code> instance with a given name.
* This constructor implements operation newChatter in the
* <a href="chatroom.maude">Chatter specification</a>.
*
* @param n the name for this Chatter
*/
public Chatter(String n)
{
name = n;
}
/**
* Return the {@link #name name} of the Chatter.
* This method implements operation getName in the
* <a href="chatroom.maude">Chatter specification</a>.
*
* @return the {@link #name name} of the Chatter
*/
public String getName()
{
return name;
}
/**
* Send a message across the network to the remote user.
*
* @param msg the msg to be sent
*/
public void sendToUser(String msg)
{
}
Chatter theChatter;
/**
* Pointer to the tail of the list.
* Default scope modifier, so that this field can be efficiently
* accessed in class ChatterList.
*
*/
Chatter next;
/**
* Creates a new <code>ChatterNode</code> instance.
*
* @param c the Chatter at this node
* @param next the tail of this list
*/
public Chatter(Chatter c, Chatter next)
{
this.next = next;
theChatter = c;
}
}
Re: variable might not have been initialized!!
Assign the variable a default value when you define it.
Re: variable might not have been initialized!!
Thanks for the reply again Norm!
I assume that by this you mean that when I define variable name I should set it as something, i.e.
However I can't do this because it is a final string. If I get rid of the final, I get the old "could not find symbol" on x!
Am I completely off track?
Re: variable might not have been initialized!!
What is x? It doesn't appear to be a String. Why not get rid of final and assign name an initial value that makes more sense like ""?
Re: variable might not have been initialized!!
Try adding another constructor that sets a value for the variable so that the compiler will know that the variable has been given a value.