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

Ribbit App Not Working

I'm working on the ribbit app. I' m on the "Modifying Fragments From The Template" video. The only thing I changed is the application name (I named it Textly). Now when I try to run the app it says "Textly has stopped". How can I fix this problem? Here is my logcat:

04-06 12:10:24.090: D/dalvikvm(25289): Late-enabling CheckJNI 04-06 12:10:24.363: I/dalvikvm(25289): Could not find method android.database.Cursor.getNotificationUri, referenced from method com.parse.ParseSQLiteCursor.getNotificationUri 04-06 12:10:24.363: W/dalvikvm(25289): VFY: unable to resolve interface method 471: Landroid/database/Cursor;.getNotificationUri ()Landroid/net/Uri; 04-06 12:10:24.363: D/dalvikvm(25289): VFY: replacing opcode 0x72 at 0x0002 04-06 12:10:24.465: D/dalvikvm(25289): GC_CONCURRENT freed 289K, 5% free 7762K/8135K, paused 2ms+5ms 04-06 12:10:24.621: I/MainActivity(25289): Jordan 04-06 12:10:24.621: D/AndroidRuntime(25289): Shutting down VM 04-06 12:10:24.621: W/dalvikvm(25289): threadid=1: thread exiting with uncaught exception (group=0x40a9e1f8) 04-06 12:10:24.629: E/AndroidRuntime(25289): FATAL EXCEPTION: main 04-06 12:10:24.629: E/AndroidRuntime(25289): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jordanpeterson.textly/com.jordanpeterson.textly.MainActivity}: java.lang.NullPointerException 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2030) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2055) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.ActivityThread.access$600(ActivityThread.java:127) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1176) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.os.Handler.dispatchMessage(Handler.java:99) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.os.Looper.loop(Looper.java:137) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.ActivityThread.main(ActivityThread.java:4532) 04-06 12:10:24.629: E/AndroidRuntime(25289): at java.lang.reflect.Method.invokeNative(Native Method) 04-06 12:10:24.629: E/AndroidRuntime(25289): at java.lang.reflect.Method.invoke(Method.java:511) 04-06 12:10:24.629: E/AndroidRuntime(25289): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 04-06 12:10:24.629: E/AndroidRuntime(25289): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 04-06 12:10:24.629: E/AndroidRuntime(25289): at dalvik.system.NativeStart.main(Native Method) 04-06 12:10:24.629: E/AndroidRuntime(25289): Caused by: java.lang.NullPointerException 04-06 12:10:24.629: E/AndroidRuntime(25289): at com.jordanpeterson.textly.MainActivity.onCreate(MainActivity.java:54) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.Activity.performCreate(Activity.java:4635) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 04-06 12:10:24.629: E/AndroidRuntime(25289): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1994) 04-06 12:10:24.629: E/AndroidRuntime(25289): ... 11 more 04-06 12:10:24.754: D/dalvikvm(25289): GC_CONCURRENT freed 384K, 7% free 7803K/8327K, paused 1ms+2ms 04-06 12:10:25.199: D/dalvikvm(25289): GC_CONCURRENT freed 375K, 6% free 7892K/8391K, paused 1ms+3ms

9 Answers

Hi Jordan,

Out of all of that, the key bit is this:

FATAL EXCEPTION: main 04-06 12:10:24.629: E/AndroidRuntime(25289): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jordanpeterson.textly/com.jordanpeterson.textly.MainActivity}: java.lang.NullPointerException

Something you're using is pointing at nothing causing the Activity to fail. Can you post the code for MainActivity or, even better, upload the whole project to Github so we can run the whole thing.

Steve.

Hi Steve,

Thanks for writing me back. I haven't gotten the chance to learn how to use Github yet. Here is the code from my

MainActivity.java
package com.jordanpeterson.textly;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.ParseAnalytics;
import com.parse.ParseUser;

public class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

    public static final String TAG = MainActivity.class.getSimpleName();

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
     * will keep every loaded fragment in memory. If this becomes too memory
     * intensive, it may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    SectionsPagerAdapter mSectionsPagerAdapter;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    ViewPager mViewPager;

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ParseAnalytics.trackAppOpened(getIntent());

        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser == null) {
            navigateToLogin();
        }
        else {
            Log.i(TAG, currentUser.getUsername());
        }

        // Set up the action bar.
        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);


        mSectionsPagerAdapter = new SectionsPagerAdapter(this, 
                getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        // When swiping between different sections, select the corresponding
        // tab. We can also use ActionBar.Tab#select() to do this if we have
        // a reference to the Tab.
        mViewPager
                .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                    @Override
                    public void onPageSelected(int position) {
                        actionBar.setSelectedNavigationItem(position);
                    }
                });

        // For each of the sections in the app, add a tab to the action bar.
        for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
            // Create a tab with text corresponding to the page title defined by
            // the adapter. Also specify this Activity object, which implements
            // the TabListener interface, as the callback (listener) for when
            // this tab is selected.
            actionBar.addTab(actionBar.newTab()
                    .setText(mSectionsPagerAdapter.getPageTitle(i))
                    .setTabListener(this));
        }
    }

    private void navigateToLogin() {
        Intent intent = new Intent(this, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId = item.getItemId();

        if (itemId == R.id.action_logout) {
            ParseUser.logOut();
            navigateToLogin();
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
        // When the given tab is selected, switch to the corresponding page in
        // the ViewPager.
        mViewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
    }

    @Override
    public void onTabReselected(ActionBar.Tab tab,
            FragmentTransaction fragmentTransaction) {
    }




    }

When does the error occur? Just when you run it, or when you do something within the app?

Steve.

Hi Steve, The app crashes when I try to run it. I've tried it on my emulator and on my Android device. I am getting a lot of warnings in MainActivity it says "The type ActionBar.Tab is deprecated" and "The type ActionBar.tabListener is deprecated". I'm not sure if that has anything to do with it not running? Thanks again for helping me!

Jordan.

Could you zip your project and email it to me at steve [dot] r [dot] hunter [at] gmail [dot] com

I'll load it into my machine and see what I can find out.

I've been staring at code all day so I've gone blind to it ... I need to run it and work my way through it.

Steve.

I emailed you the zip file.

Received, cool. It's 23:30 here right now so that may have to wait until morning but I'll see if the emailed file works before I go for some sleep.

Steve.

Your code is in my Github repo here - that's exactly as you sent it within the 'initial commit' part.

I'll work on it from there and add further -m commits to try to solve your issue!

Steve.

Updated that and got somewhere nearer the problem ... repo is probably the same as the first one.

Get hold of a Github account. It is one of the most useful things you will ever do. And it is free! \o/

Steve.

Fixed!

I've emailed it back to you or you can pull it down from the Github links above.

Cheers!

Steve.

Hi Steve, I imported the projects into eclipse. I'm now seeing a lot of errors. It might just be eclipse messing up. I've tried cleaning and building the project. A lot of the errors are saying stuff like "ActionBar cannot be resolved to a type" and "The method isEmpty() is undefined for the type String"...etc. All the problems are happening in my activities.

Thank you, Jordan.

Did this work in the end or are you still having problems with it.

If you are, there must be something different between our respective setups. I'm not sure what that might be, though. Happy to look through that again to see what needs changing.

Steve.

Hi Steve, I am still getting a bunch of errors for some reason. I've tried the project in eclipse and in Android Studio and I'm still getting errors.

Can you take me a screen shot of Android Studio with the errors showing? I'll see what I can make of them.

Steve.

I emailed you the screenshots of the errors I keep getting. Thanks again for helping me!

Has Android Studio fully started up? It can take a while to settle down.

I'll check my code again ... it worked earlier; promise!

Your app working - http://goo.gl/mGzzOq

Not sure if this will work, but this is a link to a video of Android Studio with your app loaded, showing no errors.

http://goo.gl/e1vDSX

https://drive.google.com/file/d/0ByAW6RAWFnHjMUh6RV91aktTUHM/view?usp=sharing

Hi Steve, My app is fixed now! Thank you so much for helping me!

Jordan.

Awesome!! I hoped I helped at least a little ... that got complicated!

Shout if you run into any other problems.

Steve.