Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Joshua Rincon
seal-mask
.a{fill-rule:evenodd;}techdegree
Joshua Rincon
Front End Web Development Techdegree Student 1,577 Points

SimpleAdapter shows list but no text

I've manipulated some code from the Blog Reader app but for some reason it's only showing me the appropriate number of items that SHOULD be displayed with no actual text. Here's the code I think is relative:

if(mRSSData == null) {
            updateDisplayForError();
        } else {
            try {
                ArrayList<HashMap<String, String>> rssPosts =
                        new ArrayList<HashMap<String, String>>();
                for (int i = 0; i < mRSSData.size(); i++) {

                    String title = Html.fromHtml(mRSSData.get(i)).toString();

                    System.out.println("THIS IS FROM HANDLERSS RESPONSE" + title);

                    HashMap<String, String> rssPost = new HashMap<String, String>();
                    rssPost.put("KEY_TITLE", title);
                    rssPost.put("KEY_AUTHOR", "josh");
                    rssPosts.add(rssPost);

                }

                String[] keys  = {KEY_TITLE, KEY_AUTHOR};
                int[] ids = { android.R.id.text1, android.R.id.text2};
                SimpleAdapter adapter = new SimpleAdapter(this, rssPosts,
                        android.R.layout.simple_list_item_2, keys, ids);
                setListAdapter(adapter);

            } catch (Exception e) {
                logException(e);
            }
        }

and this part:

protected List<String> doInBackground(Object[] objects) {

            int responseCode;

            List<String> sourceCode;
            String tempString = "";

            try {
                URL rssFeedUrl = new URL("http://feeds.feedburner.com/TechCrunch/startups");
                HttpURLConnection connection = (HttpURLConnection) rssFeedUrl.openConnection();
                connection.connect();

                responseCode = connection.getResponseCode();


                if (responseCode == HttpURLConnection.HTTP_OK) {

                    BufferedReader reader = new BufferedReader(new InputStreamReader(rssFeedUrl.openStream()));

                    String line;

                    while ((line = reader.readLine()) != null) {
                        if(line.contains("<title>")) {
                            int firstPos = line.indexOf("<title>");
                            String temp = line.substring(firstPos);
                            temp = temp.replace("<title>", "");
                            int lastPos = temp.indexOf("</title>");
                            temp = temp.substring(0, lastPos);
                            tempString += temp+"\n";
                            System.out.print(tempString);
                        } // end if statement
                    } // end while loop


                } else{
                    Log.i(TAG, "Unsuccessful HTTP Response Code: " + responseCode);
                }


            } catch (MalformedURLException e) {
                logException(e);
                e.printStackTrace();
            } catch (IOException e) {
                logException(e);
                e.printStackTrace();
            } catch (Exception e) {
                 logException(e);
                 e.printStackTrace();
             }

            List<String> list = Arrays.asList(tempString.split("\\n"));
            sourceCode = new ArrayList<String>(list);

            return sourceCode;
        }

I've spent the last 3 hours trying everything. Still super noob but learning! Let me know what else I can try to help debug it.

1 Answer

Joshua Rincon
seal-mask
.a{fill-rule:evenodd;}techdegree
Joshua Rincon
Front End Web Development Techdegree Student 1,577 Points

Omg I am an idiot. My mistake was making KEY_TITLE into a string "KEY_TITLE". Seriously 3 hours of not looking at my code carefully. Take that, me.