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

Jeremy Miller
Jeremy Miller
2,455 Points

AsyncTask challenge

I'm having an issue returning an empty string I have gone through everything I can think of. can anyone lead me in the right direction here please. I pay really close attention to instruction and videos but for some reason can not get an empty string to return

package com.example;

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

public class MainListActivity extends ListActivity {

    public static final String URL = "http://www.teamtreehouse.com";
    public static final String TAG = MainListActivity.class.getSimpleName();

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

        try {
            URL treehouseUrl = new URL(URL);
            HttpURLConnection connection = (HttpURLConnection) treehouseUrl.openConnection();
            connection.connect();
            int responseCode = connection.getResponseCode();
        }
        catch (MalformedURLException e) {
            Log.e(TAG, "MalformedURLException caught!", e);
        }
        catch (IOException e) {
            Log.e(TAG, "IOException caught!", e);
        }
    }
   private class CustomAsyncTask extends AsyncTask<Object, Void, String>{
     @Override
     protected String doInBackground(Object... params) {
     return "";
     }

      }
}

3 Answers

Jeremy Miller
Jeremy Miller
2,455 Points
package com.example;

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

public class MainListActivity extends ListActivity {

    public static final String URL = "http://www.teamtreehouse.com";
    public static final String TAG = MainListActivity.class.getSimpleName();

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

        try {
            URL treehouseUrl = new URL(URL);
            HttpURLConnection connection = (HttpURLConnection) treehouseUrl.openConnection();
            connection.connect();
            int responseCode = connection.getResponseCode();
        }
        catch (MalformedURLException e) {
            Log.e(TAG, "MalformedURLException caught!", e);
        }
        catch (IOException e) {
            Log.e(TAG, "IOException caught!", e);
        }
    }
   private class CustomAsyncTask extends AsyncTask<Object, Void, String>{
     @Override
     protected String doInBackground(Object... params) {
    return "";
     }

      }
}
Jeremy Miller
Jeremy Miller
2,455 Points

for some reason I can place all the code here

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

If I paste your exact code in I am passing the challenge. If you are still having problems, can you take a screenshot and link to it in here or send it to help@teamtreehouse.com?

When you paste, surround your code with three backticks and "java" on the line before it and three backticks on the line below it, like this:

```java

String test = "This is a test";

```

``java String test = "This is a test";

To link to an image, upload it to a site like imgur and link to it with Markdown syntax. See the Markdown Cheatsheet linked below the comment box.

`![alt text](http://somesite.com/path/to/img.jpg "Title")`
Jeremy Miller
Jeremy Miller
2,455 Points

yes I was having an issue with the code challenge site the next day I did it again and it excepted it. I'm sorry I should have posted back solved. though this isn't the first time I had issues with it. Usually if I wait a day it will work right. again I cant thank you enough for the help.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Cool - I'm just glad you got it working! :)