我一直在嘗試通過DocumentBuilder.Parse
解析一些XML:爲什麼DocumentBuilder Parse在Eclipse中工作正常,但不是IntelliJ IDEA?
try
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in);
return doc;
}
catch (Exception e)
{
e.printStackTrace();
}
這工作在Eclipse罰款,並返回Document
。
然而,IntelliJ IDEA的運行代碼打Document doc = builder.parse(in);
然後跳過直接過去整個try/catch語句並在try/catch語句後直接返回null
(或其他代碼可能會在那裏)。
它沒有拋出任何異常,也沒有提供任何跡象表明它爲什麼會失敗!
有沒有人知道爲什麼會發生這種情況?我真的不想回到Eclipse
編輯 - 演示:
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpClient.execute(httpPost, localContext);
InputStream in = response.getEntity().getContent();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in); //if we step through to here, this line executes then goes directly to "x" below
return doc;
} catch (Exception e) {
e.printStackTrace();
}
return null; //x
還試圖加入以下捕獲錯誤,這些都不被擊中之一:
builder.setErrorHandler(new ErrorHandler() {
@Override
public void error(SAXParseException arg0) throws SAXException
{
throw arg0;
}
@Override
public void fatalError(SAXParseException arg0) throws SAXException
{
throw arg0;
}
@Override
public void warning(SAXParseException arg0) throws SAXException
{
throw arg0;
}
});
EDIT 2 :進口
import java.io.InputStream;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.google.android.gms.maps.model.LatLng;
import android.content.Context;
import android.util.Log;
我會失效理念緩存(見行動迅速菜單'的失效caches'),重建項目('重建project'),重新部署並再試一次。另外''catch'塊中的Log.e(「」,「Exception」,e)'可能有助於診斷。 – 2013-08-05 05:53:15
喜RC - 感謝清理後,是清晨;)我試着做了這一點,但遺憾的是它還是直接跳轉過去的回報。我已經更新的問題,以進一步展示與 –