Java 虽然我没有println,但错误是什么
这个错误指出了什么Java 虽然我没有println,但错误是什么,java,android,Java,Android,这个错误指出了什么 10-31 21:05:27.567 2496-2522/com.example.talha.appforblog E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2 Process: com.example.talha.appforblog, PID: 2496 java.lang.RuntimeException: An error occured while executing doInBackground()
10-31 21:05:27.567 2496-2522/com.example.talha.appforblog E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
Process: com.example.talha.appforblog, PID: 2496
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.d(Log.java:139)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.loadXmlFromNetworkContent(MainListActivity.java:294)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.doInBackground(MainListActivity.java:228)
at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.doInBackground(MainListActivity.java:217)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587at java.lang.Thread.run(Thread.java:818)
这是我的asynTask课程。我已经实现了2个异步任务。。第一个asynctask并没有给出任何错误,但当我实现这个(第二个)asynctask时,这就是我得到的消息
private class DownloadXmlTaskContent extends AsyncTask<String, Void,List<ContentGetter.Content> > {
private Exception mException = null;
private Context mContext;
public DownloadXmlTaskContent(Context context) {
mContext = context;
}
@Override
protected List<ContentGetter.Content> doInBackground(String... urls) {
try {
return loadXmlFromNetworkContent(urls[0]);
} catch (IOException e) {
mException = e;
} catch (XmlPullParserException e) {
mException = e;
}
return null;
}
@Override
protected void onPostExecute(List<ContentGetter.Content> results) {
if (results != null && mException == null) {
} else {
if (mException instanceof IOException){
} else if (mException instanceof XmlPullParserException) {
}
}
}
private List<ContentGetter.Content> loadXmlFromNetworkContent(String urlString) throws XmlPullParserException, IOException {
InputStream stream = null;
// Instantiate the parser
ContentGetter contentgetter = new ContentGetter();
// for fetching the list view
List<ContentGetter.Content> content = null;
String summary = null;
try {
stream = downloadUrl(urlString);
content= contentgetter.parse(stream,urlBlogtitle);
Log.d(TAG,content.get(0).summary);
// Makes sure that the InputStream is closed after the app is
// finished using it.
} finally {
if (stream != null) {
stream.close();
}
}
return content;
}
// Given a string representation of a URL, sets up a connection and gets
// an input stream.
private InputStream downloadUrl(String urlString) throws IOException {
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 );
conn.setConnectTimeout(15000 );
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Starts the query
conn.connect();
return conn.getInputStream();
}
私有类下载XmlTaskContent扩展异步任务{
私有异常mException=null;
私有上下文;
公开下载XmlTaskContent(上下文){
mContext=上下文;
}
@凌驾
受保护列表doInBackground(字符串…URL){
试一试{
返回loadXmlFromNetworkContent(URL[0]);
}捕获(IOE异常){
mException=e;
}catch(XMLPullParseRexE){
mException=e;
}
返回null;
}
@凌驾
受保护的void onPostExecute(列出结果){
if(结果!=null&&mException==null){
}否则{
if(IOException的MEException实例){
}else if(XmlPullParserException的MeException实例){
}
}
}
私有列表loadXmlFromNetworkContent(字符串urlString)引发XmlPullParserException,IOException{
InputStream=null;
//实例化解析器
ContentGetter ContentGetter=新ContentGetter();
//用于获取列表视图
列表内容=空;
字符串摘要=null;
试一试{
stream=下载URL(urlString);
content=contentgetter.parse(stream,urlBlogtitle);
Log.d(TAG,content.get(0.summary));
//确保在应用程序启动后关闭InputStream
//用完了。
}最后{
if(流!=null){
stream.close();
}
}
返回内容;
}
//给定URL的字符串表示形式,设置连接并获取
//输入流。
私有InputStream downloadUrl(字符串urlString)引发IOException{
URL=新URL(URL字符串);
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
连接设置读取超时(10000);
连接设置连接超时(15000);
conn.setRequestMethod(“GET”);
conn.setDoInput(真);
//启动查询
连接();
返回连接getInputStream();
}
行中的Log.d(TAG,content.get(0.summary);
,content.get(0.summary)。summary
可能是null
在尝试打印之前,您应该检查它是否为null
,和/或在try
块中添加catch
语句
Log.d(标记,content.get(0).摘要!=null?content.get(0).摘要:“null”);
确保没有向Log.d()方法传递null。请在代码中检查它:Log.d(标记,content.get(0.summary);Log.d(标记,content.get(0.summary);Log.d(标记,content.get(0.summary);
line导致问题的原因是content.get(0).summary
返回null
。将其作为Log.d(标记,“summary::”+content.get(0.summary);
try {
stream = downloadUrl(urlString);
content= contentgetter.parse(stream,urlBlogtitle);
Log.d(TAG,content.get(0).summary != null ? content.get(0).summary : "NULL");
// Makes sure that the InputStream is closed after the app is
// finished using it.
} catch (NullPointerException e) {
Log.d("ERROR","Response is null!");
} finally {
if (stream != null) {
stream.close();
}
}