안녕하세요, Stackoverflow 프로그래머,Android AsyncTask 스레딩
저는 몇 달 전에 앱을 만들었으며 아무렇게나 작동합니다. 그러나 새로운 안드로이드 ICS에서 충돌이 시작되었습니다. 나는 그것을 찾았고 Network On Main Thread Exception을 얻었습니다. 내 코드를 재작 성하려고했지만 그것을 작동시킬 수 없습니다. 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(); */
}
});
}
}
스택 추적 또는 오류에 대한 추가 정보가 있습니까? – Theblacknight