このチュートリアルから RSS フィードを学んでみます。そのチュートリアルを読んだ後、ソースをダウンロードして RSS フィードをテストします。しかし、私のRSSにはタグmedia:contentがないため、RSSから画像を読み取ってAndroidに表示することはできませんが、次のようなタグエンクロージャーを使用しています
<enclosure url="http://p3.s1sf.com/ns/0/ud/238/1192436/1.jpg" type="image/jpeg"/>
チュートリアルからコードを実行すると、ログに次のように表示されます。
06-19 08:43:57.637: D/rssfeed(785): imageAndTexts1.get(position).getImgLink() :: null ::
そこで、startElement 関数でXmlHandler.javaを確認しました。
if (qName.equalsIgnoreCase("media:content"))
{
if (!atts.getValue("url").toString().equalsIgnoreCase("null")) {
feedStr.setImgLink(atts.getValue("url").toString());
} else {
feedStr.setImgLink("");
}
}
私は
if (qName.equalsIgnoreCase("enclosure"))
{
if (!atts.getValue("url").toString().equalsIgnoreCase("null")) {
feedStr.setImgLink(atts.getValue("url").toString());
} else {
feedStr.setImgLink("");
}
}
しかし、このようなエラーが表示されます
06-19 08:08:09.165: E/AndroidRuntime(2661): FATAL EXCEPTION: main
06-19 08:08:09.165: E/AndroidRuntime(2661): android.os.NetworkOnMainThreadException
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
06-19 08:08:09.165: E/AndroidRuntime(2661): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
06-19 08:08:09.165: E/AndroidRuntime(2661): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
06-19 08:08:09.165: E/AndroidRuntime(2661): at java.net.InetAddress.getAllByName(InetAddress.java:214)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:282)
06-19 08:08:09.165: E/AndroidRuntime(2661): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
06-19 08:08:09.165: E/AndroidRuntime(2661): at com.amit.adapter.RssReaderListAdapter.getView(RssReaderListAdapter.java:64)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.AbsListView.obtainView(AbsListView.java:2159)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.ListView.makeAndAddView(ListView.java:1831)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.ListView.fillDown(ListView.java:674)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.ListView.fillFromTop(ListView.java:735)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.ListView.layoutChildren(ListView.java:1652)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.AbsListView.onLayout(AbsListView.java:1994)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.View.layout(View.java:14008)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.View.layout(View.java:14008)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.View.layout(View.java:14008)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.View.layout(View.java:14008)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.View.layout(View.java:14008)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.Choreographer.doFrame(Choreographer.java:532)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.os.Handler.handleCallback(Handler.java:725)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.os.Handler.dispatchMessage(Handler.java:92)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.os.Looper.loop(Looper.java:137)
06-19 08:08:09.165: E/AndroidRuntime(2661): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-19 08:08:09.165: E/AndroidRuntime(2661): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 08:08:09.165: E/AndroidRuntime(2661): at java.lang.reflect.Method.invoke(Method.java:511)
06-19 08:08:09.165: E/AndroidRuntime(2661): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-19 08:08:09.165: E/AndroidRuntime(2661): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-19 08:08:09.165: E/AndroidRuntime(2661): at dalvik.system.NativeStart.main(Native Method)
タグ media:content とエンクロージャーの両方の RSS から画像を読み取る方法がわかりません。私を助けてください。