前提・実現したいこと
現在、Android Studioを使ってRSSリーダーなるものを開発しようとしています。
RSSを取得しListViewに表示させたいのですが、ListViewの出現すら確認できません。ご助力願います。エラーがなんなのかわからないのでLogCatのものを一通り載せておきます。よろしくお願いします。
発生している問題・エラーメッセージ
05-14 04:27:47.964 22965-22965/? I/le.user.rssmai: Not late-enabling -Xcheck:jni (already on) 05-14 04:27:48.002 22965-22965/? W/le.user.rssmai: Unexpected CPU variant for X86 using defaults: x86 05-14 04:27:48.131 22965-22965/com.example.user.rssmain I/le.user.rssmai: The ClassLoaderContext is a special shared library. 05-14 04:27:48.253 22965-22965/com.example.user.rssmain W/le.user.rssmai: JIT profile information will not be recorded: profile file does not exits. 05-14 04:27:48.257 22965-22965/com.example.user.rssmain I/chatty: uid=10087(com.example.user.rssmain) identical 10 lines 05-14 04:27:48.257 22965-22965/com.example.user.rssmain W/le.user.rssmai: JIT profile information will not be recorded: profile file does not exits. 05-14 04:27:48.345 22965-22965/com.example.user.rssmain I/InstantRun: starting instant run server: is main process 05-14 04:27:48.731 22965-22965/com.example.user.rssmain W/le.user.rssmai: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection) 05-14 04:27:48.733 22965-22965/com.example.user.rssmain W/le.user.rssmai: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection) 05-14 04:27:48.897 22965-22984/com.example.user.rssmain D/NetworkSecurityConfig: No Network Security Config specified, using platform default 05-14 04:27:48.907 22965-22965/com.example.user.rssmain D/OpenGLRenderer: HWUI GL Pipeline 05-14 04:27:48.997 22965-22986/com.example.user.rssmain I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 05-14 04:27:48.998 22965-22986/com.example.user.rssmain I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0 05-14 04:27:48.998 22965-22986/com.example.user.rssmain I/OpenGLRenderer: Initialized EGL, version 1.4 05-14 04:27:48.998 22965-22986/com.example.user.rssmain D/OpenGLRenderer: Swap behavior 1 05-14 04:27:48.999 22965-22986/com.example.user.rssmain W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 05-14 04:27:48.999 22965-22986/com.example.user.rssmain D/OpenGLRenderer: Swap behavior 0 05-14 04:27:49.012 22965-22986/com.example.user.rssmain D/EGL_emulation: eglCreateContext: 0xe3d85300: maj 3 min 0 rcv 3 05-14 04:27:49.046 22965-22986/com.example.user.rssmain D/EGL_emulation: eglMakeCurrent: 0xe3d85300: ver 3 0 (tinfo 0xe3d83460) 05-14 04:27:49.237 22965-22986/com.example.user.rssmain D/EGL_emulation: eglMakeCurrent: 0xe3d85300: ver 3 0 (tinfo 0xe3d83460)
該当のソースコード
java
1MainActivity.java 2 3public class MainActivity extends AppCompatActivity { 4 5 @Override 6 protected void onCreate(Bundle savedInstanceState) { 7 super.onCreate(savedInstanceState); 8 setContentView(R.layout.activity_main); 9 10 //AsyncAppTask呼び出し 11 AsyncAppTask task = new AsyncAppTask(); 12 task.execute("http://www.atsutajingu.or.jp/jingu/rss.xml"); 13 14 //ListViewに表示する文字列を生成する 15 List<Map<String, String>> dataList = new ArrayList<Map<String,String>>(); 16 for(int item = 0; item < RssList.title.size(); item++){ 17 Map<String, String> map = new HashMap<String, String>(); 18 map.put("title", RssList.title.get(item)); 19 map.put("link", RssList.link.get(item)); 20 dataList.add(map); 21 } 22 23 //ListViewに設定するデータ(アダプタ)を生成する 24 SimpleAdapter adapter = new SimpleAdapter(this, dataList, 25 android.R.layout.simple_list_item_2, 26 new String[]{"title", "link"}, 27 new int[]{android.R.id.text1, android.R.id.text2}); 28 29 //ListViewにデータ(アダプタ)を追加する 30 ListView listView = (ListView) findViewById(R.id.listView); 31 listView.setAdapter(adapter); 32 33 } 34} 35 36 37AsyncAppTask.java 38 39public class AsyncAppTask extends AsyncTask<String, Void, Void> { 40 41 private String RSS_URL = ""; 42 43 @Override 44 protected Void doInBackground(String... url) { 45 46 //情報をクリア 47 RssList.title.clear(); 48 RssList.link.clear(); 49 50 try 51 { 52 RSS_URL = url[0]; 53 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 54 DocumentBuilder builder = factory.newDocumentBuilder(); 55 56 Document document = builder.parse(RSS_URL); 57 58 //?ドキュメントのルートを取得 59 Element root = document.getDocumentElement(); 60 61 //?ルート直下の"channel"に含まれるノードリストを取得?? 62 NodeList channel = root.getElementsByTagName("channel"); 63 64 //?"channel"直下の"title"に含まれるノードリストを取得?? 65 NodeList title = ((Element)channel.item(0)).getElementsByTagName("title"); 66 67 //?メインタイトルを取得する?? 68 RssList.maintitle = new String("タイトル:" + title.item(0).getFirstChild().getNodeValue()); 69 70 //?各"item"とその中の"title"と"link"を取得する。??????? 71 NodeList item_list = root.getElementsByTagName("item"); 72 73 //?item分ループする?? 74 for(int i = 0; i < item_list.getLength(); i++) { 75 Element element = (Element) item_list.item(i); 76 77 //?title?を取得する?? 78 NodeList item_title = element.getElementsByTagName("title"); 79 80 //?link?を取得する?? 81 NodeList item_link = element.getElementsByTagName("link"); 82 83 //取得した情報をArrayListにそれぞれ格納する 84 RssList.title.add(new String(item_title.item(0).getFirstChild().getNodeValue())); 85 RssList.link.add(new String(item_link.item(0).getFirstChild().getNodeValue())); 86 } 87 } catch (ParserConfigurationException e) { 88 e.printStackTrace(); 89 } catch (SAXException e) { 90 e.printStackTrace(); 91 } catch (IOException e ) { 92 e.printStackTrace(); 93 } 94 return null; 95 } 96} 97 98 99RssList.java 100 101public class RssList { 102 103 public static String maintitle; 104 public static ArrayList<String> title = new ArrayList<String>(); 105 106 public static ArrayList<String> link = new ArrayList<String>(); 107 108} 109
試したこと
①値が配列などにしっかりと格納されているかを確認しました。
②非同期処理ではなくクラスを作ってAsyncAppTaskと同じ処理をさせてみた。(うまくいきませんでした)
補足情報(FW/ツールのバージョンなど)
その他項目を載せておきます。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.user.rssmain">
</manifest><application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ListView android:id="@+id/listView" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/15 01:33
2018/05/15 04:40 編集
2018/05/15 04:41
2018/05/15 22:34
2018/05/16 09:08