SherlockListFtagment と xml パーサーに問題があります。AsyncTask で動作する ListActivitiy では、問題はありません。ListFragment で作業するために編集する必要があるもの。
コード:
public class AndroidFragment extends SherlockListFragment{
static final String URL = "http://...";
// XML node keys
static final String KEY_ITEM = "novost"; // parent node
//static final String KEY_ID = "id";
static final String KEY_NAME = "naslov";
static final String KEY_COST = "datum";
static final String KEY_DESC = "text";
static final String KEY_LINK = "link";
static final String KEY_LINK1 = "doc";
ArrayList<HashMap<String, String>> menuItems;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view =inflater.inflate(R.layout.activity_main, null);
Log.w("Aplikacija_view","Startovana" );
return view;
}
@Override
public void onResume() {
Log.w("Aplikacija_resume","Startovana" );
new loadListView().execute();
}
public class loadListView extends AsyncTask<Integer, String, String>
{
@Override protected void onPreExecute()
{
Toast.makeText(getActivity(), "Ucitavanje...", Toast.LENGTH_LONG).show();
super.onPreExecute();
}
@Override protected String doInBackground(Integer... args)
{ // updating UI from Background Thread
menuItems = new ArrayList<HashMap<String, String>>();
final XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
map.put(KEY_COST, "Datum: " + parser.getValue(e, KEY_COST));
map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
map.put(KEY_LINK, parser.getValue(e, KEY_LINK));
map.put(KEY_LINK1, parser.getValue(e, KEY_LINK1));
// adding HashList to ArrayList
menuItems.add(map);
}
return null;
}
@Override protected void onPostExecute(String args)
{
Toast.makeText(getActivity(), "Ucitano", Toast.LENGTH_LONG).show();
String[] from = { KEY_NAME, KEY_DESC, KEY_COST,KEY_LINK,KEY_LINK1};
/** Ids of views in listview_layout */
int[] to = { R.id.naslov, R.id.novost, R.id.datum,R.id.link,R.id.link1};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), menuItems, R.layout.listview_layout, from, to);
// Setting the adapter to the listView
setListAdapter(adapter);
}
}
}
アプリケーションは常にクラッシュします。何を編集する必要がありますか?
** * ****更新ログ* ** * ** * ** * ** *
03-19 23:44:40.203: W/Aplikacija_view(30386): Startovana
03-19 23:44:40.233: W/Aplikacija_resume(30386): Startovana
03-19 23:44:40.243: W/asset(30386): deep redirect failure from 0x01030046 => 0x0a07000c, defStyleAttr=0x01010084, defStyleRes=0x0103008f, style=0x00000000
03-19 23:44:40.243: W/asset(30386): deep redirect failure from 0x01030046 => 0x0a07000c, defStyleAttr=0x01010084, defStyleRes=0x0103008f, style=0x00000000
03-19 23:44:40.413: D/AndroidRuntime(30386): Shutting down VM
03-19 23:44:40.413: W/dalvikvm(30386): threadid=1: thread exiting with uncaught exception (group=0x4200fa08)
03-19 23:44:40.423: E/AndroidRuntime(30386): FATAL EXCEPTION: main
03-19 23:44:40.423: E/AndroidRuntime(30386): java.lang.RuntimeException: Unable to resume activity {in.wptrafficanalyzer.actionbarsherlocknavtabwithimages/in.wptrafficanalyzer.actionbarsherlocknavtabwithimages.MainActivity}: android.support.v4.app.SuperNotCalledException: Fragment AndroidFragment{42678970 #0 id=0x1020002 android} did not call through to super.onResume()
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2875)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2904)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.ActivityThread.access$600(ActivityThread.java:156)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1250)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.os.Looper.loop(Looper.java:137)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.ActivityThread.main(ActivityThread.java:5234)
03-19 23:44:40.423: E/AndroidRuntime(30386): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 23:44:40.423: E/AndroidRuntime(30386): at java.lang.reflect.Method.invoke(Method.java:525)
03-19 23:44:40.423: E/AndroidRuntime(30386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
03-19 23:44:40.423: E/AndroidRuntime(30386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
03-19 23:44:40.423: E/AndroidRuntime(30386): at dalvik.system.NativeStart.main(Native Method)
03-19 23:44:40.423: E/AndroidRuntime(30386): Caused by: android.support.v4.app.SuperNotCalledException: Fragment AndroidFragment{42678970 #0 id=0x1020002 android} did not call through to super.onResume()
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:919)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:1820)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:412)
03-19 23:44:40.423: E/AndroidRuntime(30386): at com.actionbarsherlock.app.SherlockFragmentActivity.onPostResume(SherlockFragmentActivity.java:69)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.Activity.performResume(Activity.java:5230)
03-19 23:44:40.423: E/AndroidRuntime(30386): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2865)
03-19 23:44:40.423: E/AndroidRuntime(30386): ... 12 more