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

EditFriendsActivity won't open in Ribbit Application

When I run the ribbit application and try to open the EditFriendsActivity tab. I get this error code in my logcat:

07-22 06:06:35.649: E/AndroidRuntime(5503): FATAL EXCEPTION: main 07-22 06:06:35.649: E/AndroidRuntime(5503): java.lang.NullPointerException 07-22 06:06:35.649: E/AndroidRuntime(5503): at com.jordanpeterson.textly.adapters.UserAdapter.getView(UserAdapter.java:49) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.AbsListView.obtainView(AbsListView.java:2033) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.GridView.makeAndAddView(GridView.java:1323) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.GridView.makeRow(GridView.java:328) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.GridView.fillDown(GridView.java:281) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.GridView.fillFromTop(GridView.java:403) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.GridView.layoutChildren(GridView.java:1215) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.AbsListView.onLayout(AbsListView.java:1863) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.View.layout(View.java:11284) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.ViewGroup.layout(ViewGroup.java:4232) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:925) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.View.layout(View.java:11284) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.ViewGroup.layout(ViewGroup.java:4232) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.FrameLayout.onLayout(FrameLayout.java:431) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.View.layout(View.java:11284) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.ViewGroup.layout(ViewGroup.java:4232) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.View.layout(View.java:11284) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.ViewGroup.layout(ViewGroup.java:4232) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.widget.FrameLayout.onLayout(FrameLayout.java:431) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.View.layout(View.java:11284) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.ViewGroup.layout(ViewGroup.java:4232) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1497) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2453) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.os.Handler.dispatchMessage(Handler.java:99) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.os.Looper.loop(Looper.java:137) 07-22 06:06:35.649: E/AndroidRuntime(5503): at android.app.ActivityThread.main(ActivityThread.java:4429) 07-22 06:06:35.649: E/AndroidRuntime(5503): at java.lang.reflect.Method.invokeNative(Native Method) 07-22 06:06:35.649: E/AndroidRuntime(5503): at java.lang.reflect.Method.invoke(Method.java:511) 07-22 06:06:35.649: E/AndroidRuntime(5503): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:3151) 07-22 06:06:35.649: E/AndroidRuntime(5503): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:2918) 07-22 06:06:35.649: E/AndroidRuntime(5503): at dalvik.system.NativeStart.main(Native Method)

Here is my UserAdapter code: import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.TextView;

import com.jordanpeterson.textly.R; import com.jordanpeterson.textly.utils.MD5Util; import com.parse.ParseUser; import com.squareup.picasso.Picasso;

public class UserAdapter extends ArrayAdapter<ParseUser> {

protected Context mContext;
protected List<ParseUser> mUsers;

public UserAdapter(Context context, List<ParseUser> users) {
    super(context, R.layout.message_item, users);
    mContext = context;
    mUsers = users;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(
                R.layout.user_item, null);
        holder = new ViewHolder();
        holder.userImageView = (ImageView) convertView
                .findViewById(R.id.userImageView);
        holder.nameLabel = (TextView) convertView.findViewById(R.id.nameLabel);
        holder.checkImageView = (ImageView) convertView
                .findViewById(R.id.checkImageView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    ParseUser user = mUsers.get(position);
    String email = user.getEmail().toLowerCase();

    if (email.equals("")) {
        holder.userImageView.setImageResource(R.drawable.avatar_empty);
    } else {
        String hash = MD5Util.md5Hex(email);
        String gravatarUrl = "http://www.gravatar.com/avatar/" + hash
                + "?s=204&d=404";
        Picasso.with(mContext).load(gravatarUrl)
                .placeholder(R.drawable.avatar_empty)
                .into(holder.userImageView);
    }

    holder.nameLabel.setText(user.getUsername());

    GridView gridView = (GridView) parent;
    if (gridView.isItemChecked(position)) {
        holder.checkImageView.setVisibility(View.VISIBLE);
    } else {
        holder.checkImageView.setVisibility(View.INVISIBLE);
    }

    return convertView;
}

private static class ViewHolder {
    ImageView userImageView;
    ImageView checkImageView;
    TextView nameLabel;
}

public void refill(List<ParseUser> users) {
    mUsers.clear();
    mUsers.addAll(users);
    notifyDataSetChanged();
}

}

2 Answers

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hey,

That is an error for sure. The best way to do this. Would be to create breakpoints. I would start it at the if contentview and place a whole bunch of them.

Then run the app in debug mode. That way in the upper (your right) you can see all the variables and expand each one of them. You can follow the code down and step into some of the conditions to see exactly which one is throwing a null. It will have a null as the value.

Sorry I can't be more precise, but that is what I would try and do. Let us know if you found out the problem already or if you have made any progress.

Hi Ryan, I'm still trying to figure out where the error is. I don't really know how to use the debugger yet. I did figure out that the app keeps crashing at this line:

String email = user.getEmail().toLowerCase();

I just don't know how to fix it.

Hi all!

Jordan have you found a fix for this yet as I'm experiencing the same error.

Thanks