gpt4 book ai didi

c# - 我编写的函数中出现奇怪的空引用异常

转载 作者:太空宇宙 更新时间:2023-11-03 16:35:51 27 4
gpt4 key购买 nike

private void GoogleTalkClient_OnMessage(object sender, jabber.protocol.client.Message msg)
{
connectionsNumber.Maximum = rosterManager.Count;
if (session.Keys.Contains<string>(msg.From.Bare)){

session.TryGetValue(msg.From.Bare,out thissession);

}else{
if (cleverbot.Keys.Contains<string>(msg.From.Bare)){
cleverbot.TryGetValue(msg.From.Bare,out bot);
}else{
bot = factory.Create(ChatterBotType.CLEVERBOT);
if (bot != null)
cleverbot.Add(msg.From.Bare, bot);
}
thissession = bot.CreateSession();
if (thissession != null)
session.Add(msg.From.Bare, thissession);
}
connectionsNumber.Value = session.Count;
jabber.protocol.client.Message reply = new jabber.protocol.client.Message(GoogleTalkClient.Document);
reply.Body = thissession.Think(Grammarcheck(msg.Body));
reply.To = msg.From;
GoogleTalkClient.Write(reply);
}

代码是 C# 并且它在所有 session.Add() 和 cleverbot.Add() 语句上给我 nullreference 错误,我不明白为什么(cleverbot 和 session 是字典)

最佳答案

字典没有正确初始化

关于c# - 我编写的函数中出现奇怪的空引用异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9152621/

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