java.lang.StackOverflowError trying to parse in a AsyncTask(试图在 AsyncTask 中解析的 java.lang.StackOverflowError)
问题描述
上一个问题.在我之前的问题中,我询问了如何在 AsyncTask
中使用 AndroidSaxParser
.所以这个问题没有对我有用的好的答案,我曾经尝试过一些事情.正如标题所说,我的 LogCat
抛出一个错误,我不知道如何解决是我尝试了很多东西,但最终没有出现任何语法错误.
Previous question. In my previous question I asked about how to us a AndroidSaxParser
in a AsyncTask
. So that question had no good answer which worked for me and I used tried some things out. As the title says my LogCat
throws an error and I don't know how to fix is I have tried a lot of things and I finally didn't get any syntax errors.
我的活动代码:
package org.developerworks.android;
import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MessageList extends ListActivity
{
private List<Message> messages;
DownloadWebPageTask task = new DownloadWebPageTask();
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
task.execute();
// loadFeed(ParserType.ANDROID_SAX);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, ParserType.ANDROID_SAX.ordinal(), ParserType.ANDROID_SAX.ordinal(), R.string.android_sax);
menu.add(Menu.NONE, ParserType.SAX.ordinal(), ParserType.SAX.ordinal(), R.string.sax);
menu.add(Menu.NONE, ParserType.DOM.ordinal(), ParserType.DOM.ordinal(), R.string.dom);
menu.add(Menu.NONE, ParserType.XML_PULL.ordinal(), ParserType.XML_PULL.ordinal(), R.string.pull);
return true;
}
@SuppressWarnings("unchecked")
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item)
{
super.onMenuItemSelected(featureId, item);
ParserType type = ParserType.values()[item.getItemId()];
ArrayAdapter<String> adapter = (ArrayAdapter<String>) this.getListAdapter();
if (adapter != null)
{
if (adapter.getCount() > 0)
{
adapter.clear();
}
}
task.execute();
// this.loadFeed(type);
return true;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
Intent viewMessage = new Intent(Intent.ACTION_VIEW, Uri.parse(messages.get(position).getLink().toExternalForm()));
this.startActivity(viewMessage);
}
private void loadFeed(ParserType type)
{
try
{
Log.i("AndroidNews", "ParserType=" + type.name());
FeedParser parser = FeedParserFactory.getParser(type);
messages = parser.parse();
List<String> titles = new ArrayList<String>(messages.size());
for (Message msg : messages)
{
titles.add(msg.getTitle());
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, titles);
this.setListAdapter(adapter);
}
catch (Throwable t)
{
Log.e("AndroidNews", t.getMessage(), t);
}
}
private class DownloadWebPageTask extends AsyncTask<List<String>, Void, List<String>>
{
MessageList msgl = new MessageList();
@Override
protected List<String> doInBackground(List<String>... urls)
{
FeedParser parser = FeedParserFactory.getParser(ParserType.ANDROID_SAX);
messages = parser.parse();
List<String> titles = new ArrayList<String>(messages.size());
for (Message msg : messages)
{
titles.add(msg.getTitle());
}
return titles;
}
@Override
protected void onPostExecute(List<String> result)
{
ArrayAdapter<String> adapter = new ArrayAdapter<String>(msgl, R.layout.row, result);
msgl.setListAdapter(adapter);
}
}
}
这是它抛出的错误:
推荐答案
SOError 被抛出,因为 DownloadWebPageTask 创建了一个新的 MessageList,它创建了一个新的 DownloadWebPageTask,它创建了一个新的 MessageList,它创建了一个新的 DownloadWebPageTaskcreate一个新的 MessageList,它创建了一个新的 DownloadWebPageTask...等等.
The SOError is thrown because DownloadWebPageTask creates a new MessageList that creates a new DownloadWebPageTask that creates a new MessageList that creates a new DownloadWebPageTaskcreates a new MessageList that creates a new DownloadWebPageTask... and so on.
这篇关于试图在 AsyncTask 中解析的 java.lang.StackOverflowError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:试图在 AsyncTask 中解析的 java.lang.StackOverflowError
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01