Question

I wanted to retrieve picture store in my Parse User to be displayed on my imageview, somehow it just crashed. Basically the code in on my Profile page. I have an imagview set in my layout. My stored image is in the field named "file" and the filename is uploaded_file.png. I want it to load onto the image view and I set a listener so that it allows user to take and upload new picture.

My code as follows: Any help will be much appreciated. Many thanks.

public class ProfileActivity extends Activity {

    protected TextView mUsername;
    protected EditText mPassword;
    protected TextView mEmail;
    protected TextView mCreateAccountTextView;
    protected ParseUser mCurrentUser;
    protected List<ParseUser> mUsers;
    protected TextView chEmailbutton;
    protected TextView chPassbutton;
    protected ImageView profilePicture;
    protected Uri mMediaUri;
    protected String mFileType;
    protected ParseObject currentObject;


    protected TextView savePixButton;

     final int PIC_CROP = 1;
    //private static final String EMAIL_PATTERN = 
    //      "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
    //      + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

    private Uri mImageCaptureUri;
    private ImageView mImageView;

        private static final int PICK_FROM_CAMERA = 1;
        private static final int CROP_FROM_CAMERA = 2;
        private static final int PICK_FROM_FILE = 3;

    String username;
    String email;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.profile);

        mUsername = (TextView) findViewById(R.id.usernameField);
        mEmail = (TextView)findViewById(R.id.emailField);
        mCurrentUser = ParseUser.getCurrentUser();
        username = mCurrentUser.getUsername();
        email = mCurrentUser.getEmail();
        mUsername.setText(username);
        mEmail.setText(email);  
        mMediaUri = getIntent().getData();

        currentObject = mCurrentUser.getParseObject("file");

        ParseFile image = currentObject.getParseFile("uploaded_file.png");
        final ParseImageView imageView = (ParseImageView) findViewById(R.id.profilepix);
        imageView.setParseFile(image);
        imageView.loadInBackground(new GetDataCallback() {
             public void done(byte[] data, ParseException e) {
             // The image is loaded and displayed!                    
             int oldHeight = imageView.getHeight();
             int oldWidth = imageView.getWidth();                 
             //Log.v("LOG!!!!!!", "imageView height = " + oldHeight);      // DISPLAYS 90 px
             //Log.v("LOG!!!!!!", "imageView width = " + oldWidth);        // DISPLAYS 90 px      
             }
        });

        profilePicture = (ImageView)findViewById(R.id.profilepix);
        profilePicture.setOnClickListener(new View.OnClickListener() {

LogCat Error

05-13 23:20:44.439: E/ViewRootImpl(31057): sendUserActionEvent() mView == null
05-13 23:20:47.969: E/AndroidRuntime(31057): FATAL EXCEPTION: main
05-13 23:20:47.969: E/AndroidRuntime(31057): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fappbulously.sharemate/com.fappbulously.sharemate.ProfileActivity}: java.lang.NullPointerException
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.os.Looper.loop(Looper.java:137)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.ActivityThread.main(ActivityThread.java:5419)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at java.lang.reflect.Method.invokeNative(Native Method)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at java.lang.reflect.Method.invoke(Method.java:525)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at dalvik.system.NativeStart.main(Native Method)
05-13 23:20:47.969: E/AndroidRuntime(31057): Caused by: java.lang.NullPointerException
05-13 23:20:47.969: E/AndroidRuntime(31057):    at com.fappbulously.sharemate.ProfileActivity.onCreate(ProfileActivity.java:95)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.Activity.performCreate(Activity.java:5372)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
05-13 23:20:47.969: E/AndroidRuntime(31057):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
05-13 23:20:47.969: E/AndroidRuntime(31057):    ... 11 more
Was it helpful?

Solution

I think the problem comes from this line:

mCurrentUser.getParseObject("file");

You are trying to get a ParseObject from the "file" column on the Users table, and then trying to get a ParseFile from ParseObject that probably doesn't exists.

What you want is to retrieve a ParseFile from the Users table that resides in a column called "file". Since ParseUser inherits from ParseObject you can do this:

ParseUser.getCurrentUser().getParseFile("file")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top