【发布时间】:2012-01-31 14:14:23
【问题描述】:
尊敬的 Stackoverflow 程序员,
几个月前我制作了一个应用程序,它运行完美。但是,在新的 Android ICS 上,它开始崩溃。我查了一下,我得到一个主线程异常的网络。我试图重写我的代码,但我无法让它以它的方式工作。我尝试了 AsyncTasking,但也没有工作。请有人能帮帮我吗??
我的代码:(如果你还需要 XMLFunctions.class ,请告诉我)
package test.lmc;
import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class nieuwsflits extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nieuwsflits);
String xml = XMLfunctions.getXML();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);
if((numResults <= 0)){
Toast.makeText(nieuwsflits.this, "Nog geen resultaten gevonden...", Toast.LENGTH_LONG).show();
finish();
}
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
NodeList nodes = doc.getElementsByTagName("message");
int max = 10;
//fill in the list items from the XML document
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("id", XMLfunctions.getValue(e, "id"));
map.put("datum", XMLfunctions.getValue(e, "datum"));
map.put("message-text", XMLfunctions.getValue(e, "message-text"));
map.put("url", XMLfunctions.getValue(e, "url"));
mylist.add(map);
}
//Make a new listadapter
ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.listadapter,
new String[] { "message-text", "datum" },
new int[] { R.id.item_title, R.id.item_subtitle });
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@SuppressWarnings("unchecked")
HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
String url = o.get("url");
String check ="";
if ((url == check)) {
Toast.makeText(nieuwsflits.this, "Geen website gevonden...", Toast.LENGTH_LONG).show();
}
else {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
/** Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(o.get("url")));
startActivity(browserIntent);
Toast.makeText(nieuwsflits.this, "ID '" + o.get("url") + "' was clicked.", Toast.LENGTH_LONG).show(); */
}
});
}
}
【问题讨论】:
-
得到了堆栈跟踪,或者关于错误的更多信息?
标签: android multithreading android-asynctask android-4.0-ice-cream-sandwich