gpt4 book ai didi

java - 字符串不添加到列表 - Java

转载 作者:行者123 更新时间:2023-11-29 03:10:05 26 4
gpt4 key购买 nike

我遇到一个问题,我将字符串变量发送到服务器、从服务器、主题、消息和附件到服务器,当我将它们放在列表中时,消息变量始终为空!我已经输出了变量消息,它给出了它应该做的但是,但是一旦我把它放在列表中。它显示为空。

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);
}

样本输出

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

我什至不确定是否有人可以帮助我,但如果您需要查看更多代码,请告诉我,谢谢!

电子邮件类

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);
}
}

最佳答案

Email构造函数 有问题。您使用 messageattachment 两次分配 message 字段。

关于java - 字符串不添加到列表 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29868407/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com