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 Build a Blog Reader Android App Getting Data from the Web Trying Code and Catching Exceptions

Louis Sankey
Louis Sankey
22,595 Points

Declaring a constant String and setting it in Android

I am having trouble with declaring a constant string variable name URL and setting it to the value "teamtreehouse.com" The last line of code in the onCreate method is what I tried, among other things.

''' Java

package com.example;

import android.os.Bundle; import android.view.View; import java.net.MalformedURLException; import android.util.Log;

public class MainListActivity extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_list);

  public static final String URL = "teamtreehouse.com;


}

}

''' Any help would be appreciated.

I also don't know what I'm doing wrong in my formatting on these posts. I tried '''java... ''', so any help would be appreciated there are well.

Louis Sankey
Louis Sankey
22,595 Points

Never mind, I got it figured out. I was adding the code in the wrong place.

3 Answers

Louis Sankey
Louis Sankey
22,595 Points

Never mind. I added the code in the wrong place.

Hey Louis Sankey, I saw you already got it all sorted out but I thought I might include some information you might find of value later on down the road..possibly very soon or maybe not.

    <string name="URL">teamtreehouse.com</string>

One of the benefits to doing this is that it will allow you to not only organize your code better but to provide internationalization of your content by providing different values for different languages based upon the user's locale setting on their device.

For example, some web sites provide a sub domain for different locales ( Examles: en.gravatar.com, fr.gravatar.com , etc, etc)

Hope that was helpful even if it may have seemed pointless just for your one value

A tip is to highlight your constant and right-click, then refactor, then extract constant.

Good luck to you Louis

Louis Sankey
Louis Sankey
22,595 Points

Thanks Christopher, I appreciate the tip. The lesson that I was watching actually touched on this exact same point. It's always good to have it reinforced by hearing it in a different way, however. In addition, I appreciate the camaraderie.