我正在为推特网络课程的P2P Twitter客户端工作。我试图给我的同伴一个注册自己的方式,以便其他同行可以发现它。我正在创建一个DNS TXT记录,以便我可以调用DNSSD.Register()。但是,当调用此方法时,我收到的错误是:
导致此错误的原因(java):“位置0x0的内存访问无效rip = 0x106282bae”
以下是导致它的方法:
import com.apple.dnssd.*;
public static void announce()throws com.apple.dnssd.DNSSDException{
TXTRecord txtRec = new TXTRecord();
txtRec.set("Version", "1.1");
txtRec.set("EncryptionSupport", "false");
txtRec.set("DisplayName", profile.getPropertyValue("UserName"));
txtRec.set("UserID", profile.getPropertyValue("UserID"));
RegisterListener myRegisterListener = null;
DNSSDRegistration reg = null;
RegisterListener myRegistrationListener = null;
reg = DNSSD.register
(0, DNSSD.ALL_INTERFACES, profile.getPropertyValue("UserName"),
profile.getPropertyValue("DNSSDServiceName"),
null, null, 4444, txtRec, myRegistrationListener);
}
“reg = ...”行是导致错误发生的行。关于我做错了什么的任何想法?其中很多都来自我不完全理解的例子。
答案 0 :(得分:6)
问题是DNSSD.register()方法的最后一个参数应该是一个有效的对象。 由于您将其作为NULL指针传递,因此在调用它时,您将无法访问0x0位置。
请查看此方法的docs。
答案 1 :(得分:0)
KuarmaYoko没错。传递null RegisterListener导致了问题。 RegisterListener是一个接口,我必须在一个新类中实现,我称之为“播音员”。当我实现这个类,实例化它,并将其作为最后一个参数传递时,我的代码就像梦一样编译和执行。谢谢大家,希望这对未来的读者有所帮助!