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

aimensasi
aimensasi
11,343 Points

Setting user's profile picture when signing up to parse.com

I am trying to allow the user to choose picture and set it as his/her profile picture when signing up.

I used the following code to convert the file and to sign up the user but it throw an exception when signing up:

final ParseUser user = new ParseUser(); user.setUsername(username); user.setPassword(password); user.setEmail(email);

    Toast.makeText(SignUpActivity.this, "setting the file ", Toast.LENGTH_LONG).show();

    byte[] fileByte = FileHelper.getByteArrayFromFile(this, mMediaUri);
    if(fileByte == null){
        Log.e(TAG, "The file is null");
    }else{
        if (mFileType.equals(ParseConstant.TYPE_IMAGE)){
            fileByte = FileHelper.reduceImageForUpload(fileByte);
        }
        String fileName = FileHelper.getFileName(this, mMediaUri, mFileType);
        file = new ParseFile(fileName, fileByte);
         user.put(ParseConstant.KEY_FILE, file);
    }

user.signUpInBackground(new SignUpCallback() { @Override public void done(ParseException e) { if (e == null) { navigateToHomePage(); } else { Toast.makeText(SignUpActivity.this, "Error in sign up ", Toast.LENGTH_LONG).show(); } } });

I also tried to save the file first and then add it to the user and sign up, this time it does not throw an exception, but when I check the Parse.com I don't see any change in the data. The file is not showing in the table.

Thanks in advance.

1 Answer

Can you post the exception bein thrown? also if it's a parse exception you might replace this Toast.makeText(SignUpActivity.this, "Error in sign up ", Toast.LENGTH_LONG).show(); } by this : Toast.makeText(SignUpActivity.this, "Error in sign up :"e+getMessage(), Toast.LENGTH_LONG).show(); }