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 Getting JSON Data from an HTTP Request

Frames Skipped! (app may be doing too much work)

Hey Guys,

So this one has been giving me some difficulty... I did the TreeHouse Blog Reader Tutorial (all the code worked for their blog), tried to redo it with my wordpress blog (TechWarriorz) and it came up with the following error:

Exception caught: java.lang.NegativeArraySizeException: -1

Then it said: I/Choreographer﹕ Skipped 1405 frames! The application may be doing too much work on its main thread.

Here is a copy of my code:

public class MainListActivity extends ListActivity {

protected String[] mBlogPostTitles;
public static final int NUMBER_OF_POSTS = 20;
public static final String TAG = MainListActivity.class.getSimpleName();

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

    if (isNetworkAvailable()) {
        GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask();
        getBlogPostsTask.execute();
    }
    else {
        Toast.makeText(this, "Network is unavailable!", Toast.LENGTH_LONG).show();
    }

    //Toast.makeText(this, getString(R.string.no_items), Toast.LENGTH_LONG).show();
}

private boolean isNetworkAvailable() {
    ConnectivityManager manager = (ConnectivityManager) 
            getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();

    boolean isAvailable = false;
    if (networkInfo != null && networkInfo.isConnected()) {
        isAvailable = true;
    }

    return isAvailable;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main_list, menu);
    return true;
}

private class GetBlogPostsTask extends AsyncTask<Object, Void, String> {

    @Override
    protected String doInBackground(Object... arg0) {
        int responseCode = -1;

        try {
            URL blogFeedUrl = new URL("http://techwarriorz.com/v2/?json=1");
            HttpURLConnection connection = (HttpURLConnection) blogFeedUrl.openConnection();
            connection.connect();

            responseCode = connection.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                InputStream inputStream = connection.getInputStream();
                Reader reader = new InputStreamReader(inputStream);
                int contentLength = connection.getContentLength();
                char[] charArray = new char[contentLength];
                reader.read(charArray);
                String responseData = new String(charArray);

                JSONObject jsonResponse = new JSONObject(responseData);
                String status = jsonResponse.getString("status");
                Log.v(TAG, status);

                JSONArray jsonPosts = jsonResponse.getJSONArray("posts");
                for (int i = 0; i < jsonPosts.length(); i++) {
                    JSONObject jsonPost = jsonPosts.getJSONObject(i);
                    String title = jsonPost.getString("title");
                    Log.v(TAG, "Post " + i + ": " + title);
                }
            }
            else {
                Log.i(TAG, "Unsuccessful HTTP Response Code: " + responseCode);
            }
        }
        catch (MalformedURLException e) {
            Log.e(TAG, "Exception caught: ", e);
        }
        catch (IOException e) {
            Log.e(TAG, "Exception caught: ", e);
        }
        catch (Exception e) {
            Log.e(TAG, "Exception caught: ", e);
        }

        return "Code: " + responseCode;
    }

}

}

You guys can see a copy of my JSON data over at http://techwarriorz.com/v2/?json=20

1 Answer

I came up with the same error and got an answer that helped:

https://teamtreehouse.com/forum/skipped-60-frames-the-application-may-be-doing-too-much-work-on-its-main-threadblogreader

I'm hoping Ben Jakuben can weigh in a bit more on this showing up on this particular project.