我似乎無法弄清楚如何讓這段代碼正常工作。難道我做錯了什麼?程序在Record [] records = lookup.run();上失敗。線。Java DNS API不起作用
import java.util.Iterator;
import org.xbill.DNS.ARecord;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.TXTRecord;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
Lookup lookup;
try {
lookup = new Lookup("google.com", Type.ANY);
Record[] records = lookup.run();
if (lookup.getResult() == Lookup.SUCCESSFUL) {
String responseMessage = null;
String listingType = null;
for (int i = 0; i < records.length; i++) {
if (records[i] instanceof TXTRecord) {
TXTRecord txt = (TXTRecord) records[i];
for (Iterator j = txt.getStrings().iterator(); j.hasNext();) {
responseMessage += (String) j.next();
}
} else if (records[i] instanceof ARecord) {
listingType = ((ARecord) records[i]).getAddress()
.getHostAddress();
}
}
}
}catch (TextParseException e) {
e.printStackTrace();
}
如果失敗了通過打印堆棧跟蹤,發佈堆棧跟蹤過。 – 2011-04-21 16:03:45