Im having an issue where im sending String variables to,from,subject,message and attachment to a server and when I go to place them in a list, the message variable is always null! I have outputted the variable message, and it comes up with what its supposed to but, but as soon as I put it in the list. its shows as null.
private void doSend(String name)
{
String to = input.nextLine();
String from = input.nextLine();
String subject = input.nextLine();
String message = input.nextLine();
String attachment = input.nextLine();
System.out.println(to);
System.out.println(from);
System.out.println(subject);
System.out.println(message);
System.out.println(attachment);
// stores the message, but not into the mailbox
MultiEchoServer.MailBox.add(new Email(to, from,subject, message, attachment));
System.out.println(MailBox);
System.out.println("Message Sent to: " + to);
System.out.println(message);
}
Sample output
pj // this is the to variable
dsds // this is the from variable
subject // this is the subject variable
message // this is the message variable
[pj dsds subject null] //this is the Mailbox List
Message Sent to: pj //not part of the error
message // this is the message variable being outputted again to see it it changed
I'm not even sure if anyone can help me, but let me know if you need to see more code thanks!
The Email Class
class Email
{
private String to, from, subject, message, attachment;
int id;
public Email(String to ,String from ,String subject, String message, String attachment)
{
this.to = to;
this.from = from;
this.subject = subject;
this.message = message;
this.message = attachment;
}
public int id()
{
return(id);
}
public String to()
{
return(to);
}
public String from()
{
return(from);
}
public String subject()
{
return(subject);
}
public String message()
{
return(message);
}
public String attachment()
{
return(attachment);
}
public String toString()
{
return(to + " " + from + " " + subject + " " + message + "" + attachment);
}
}
toString()method ofMailBoxclass?this.message = attachment;Actually, that is related to the question, as it is likely setting message tonull.