Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing fragment for ListView
    primarykey
    data
    text
    <p>I am trying to populate my <code>ListView</code> with Items from an XML-File.</p> <p>I know its because I use<code>Fragments</code>, but i don't really know how i can fix it.</p> <p>StackTrace</p> <pre><code>FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iklikla.codetechblog/com.iklikla.codetechblog.FrontpageActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' at android.app.ListActivity.onContentChanged(ListActivity.java:243) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273) at android.app.Activity.setContentView(Activity.java:1881) at com.iklikla.codetechblog.FrontpageActivity.onCreate(FrontpageActivity.java:56) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)             at android.app.ActivityThread.access$600(ActivityThread.java:141)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)             at android.os.Handler.dispatchMessage(Handler.java:99)             at android.os.Looper.loop(Looper.java:137)             at android.app.ActivityThread.main(ActivityThread.java:5041)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:511) </code></pre> <p>My Activity:</p> <pre><code>public class FrontpageActivity extends ListActivity { // All static variables static final String URL = "http://blog.codetech.de/rss"; // XML node keys static final String KEY_ITEM = "item"; // parent node static final String KEY_TITLE = "title"; static final String KEY_LINK = "link"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_frontpage); ActionBar actionBar = getActionBar(); actionBar.setDisplayUseLogoEnabled(true); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()) .commit(); } ArrayList&lt;HashMap&lt;String, String&gt;&gt; menuItems = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); 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 &lt;item&gt; for (int i = 0; i &lt; nl.getLength(); i++) { // creating new HashMap HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); Element e = (Element) nl.item(i); // adding each child node to HashMap key =&gt; value map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE)); map.put(KEY_LINK, parser.getValue(e, KEY_LINK)); // adding HashList to ArrayList menuItems.add(map); } // Adding menuItems to ListView ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.list, new String[] { KEY_TITLE, KEY_LINK }, new int[] { R.id.textView, R.id.textView2 }); setListAdapter(adapter); // selecting single ListView item ListView lv = getListView(); // listening to single listitem click lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // getting values from selected ListItem String title = ((TextView) view.findViewById(R.id.textView)).getText().toString(); String link = ((TextView) view.findViewById(R.id.textView2)).getText().toString(); // Starting new intent Intent in = new Intent(getApplicationContext(), WebViewActivity.class); in.putExtra(KEY_TITLE, title); in.putExtra(KEY_LINK, link); startActivity(in); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.frontpage, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); switch (itemId) { case R.id.action_reload: Intent intent_reload = new Intent(this, FrontpageActivity.class); startActivity(intent_reload); break; case R.id.action_about: Intent intent_about = new Intent(this, AboutActivity.class); startActivity(intent_about); break; default: break; } return true; } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_frontpage, container, false); return rootView; } } } </code></pre> <p>And my fragment XML:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="com.iklikla.codetechblog.FrontpageActivity$PlaceholderFragment" android:background="@color/background_grey"&gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:entries="@array/tutorialTitle" android:background="@drawable/card"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>EDIT: Here is my activity_frontpage.xml</p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.iklikla.codetechblog.FrontpageActivity" tools:ignore="MergeRootFrame" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload