我需要帮助我正在制作代理搜寻器。我的申请是因为看似没有理由而抛出异常。
我的代码
package com.ElwynDev.PastBinBot;
import java.io.IOException;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ProxyScraper {
public static void ScrapProxy(int Pages) {
final int[] searchIds = new int[] { 225957, 278235, 240804, 258000, 227364, 244555, 438084, 438085, 438086, 438087, 438088};
final String searchUrl = "http://www.proxyfire.net/forum/showthread.php?t=56861?";
final String proxyExtractingRegex = "[1-9]{2,3}.[1-9]{2,3}.[1-9]{2,3}.[1-9]{2,3}";
Pattern r = Pattern.compile(proxyExtractingRegex);
HashSet<String> proxyHashSet = new HashSet<String>();
for(int searchId : searchIds) {
Matcher m = null;
try {
m = r.matcher(ProxyHandle.get(searchUrl + searchId, null, Pages));
while(true) {
if(m.find()){
proxyHashSet.add(m.group());
}
else
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
for(String proxy : proxyHashSet) {
FileWrighter.logTo("proxy.txt", proxy + "\n");
}
}
};
Exception in thread "main" java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Unknown Source)
at java.util.regex.Matcher.reset(Unknown Source)
at java.util.regex.Matcher.<init>(Unknown Source)
at java.util.regex.Pattern.matcher(Unknown Source)
at com.ElwynDev.PastBinBot.ProxyScraper.ScrapProxy(ProxyScraper.java:24)
at com.ElwynDev.PastBinBot.Main.main(Main.java:17)
答案 0 :(得分:1)
看起来像这样:
ProxyHandle.get(searchUrl + searchId, null, Pages)
正在返回null
。我不知道为什么。我建议使用调试器来解决这个问题。