技術的メモ

個人的な備忘録として記録を残していきます

RSS Readerのアプリ

以下の記事を参考に作ってみることにした。
Androidで広がる,携帯アプリ開発の世界 - 第4回 簡単なRSSリーダーを作ってみる:ITpro


若干、記事の内容と違う箇所もあったが概ね同じ感じに入力して早速実行してみると
「Unfortunately,(アプリ名) has stopped.」とエラーが出て起動しない・・・(´・ω・`)

エラー内容をググってみるとLogCatにエラーが出ている模様。
というわけで早速LogCatを見てみると作成したアプリから大量にエラーが・・・

その中に以下のようなエラーがありました。
「Your content must have a ListView whose id attribute is 'android.R.id.list'」
要するにListViewを利用する場合はIDを @+id/android:listしないといけないみたいです。

そこで、作成した「activity_rss_reader.xml」を見てみると
ちゃんと指定されているみたいです(´・ω・`)

activity_rss_reader.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".RssReaderActivity" >

    <ListView
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ListView>

    <TextView
        android:id="@+id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        >

        <requestFocus />
    </TextView>

</LinearLayout>

デフォルトで入っていた値にGUIで付け足して作成したのですが、
何がダメなのかわかりません_| ̄|○

ということで、記事にある通り以下のように手書きで作り変えてみました。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<ListView
		android:id="@android:id/list"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content" />
	<TextView
		android:id="@android:id/empty"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content" />
</LinearLayout>

それで、実行してみると無事に動くようになりました。
マウスで、ドラッグすると上下します。
f:id:amatuka:20140114234953j:plain

また、明日以降続きをがんばるぞ~(・ω<)