Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Nullpointer with default intent.getExtra methods #1898

Description

@rickbijkerk

See code below i have an activity which has a setResult with a byte[] as argument. However when i press the back button on said activity it crashes in the generated class because the intent is null. See code below for the error:

Bundle extras_ = (((data!= null)&&(data.getExtras()!= null))?data.getExtras():new Bundle()); byte[] bitmap = data.getByteArrayExtra(BITMAPRESULTKEY_EXTRA); ChatFragment_.this.onPictureTaken(resultCode, bitmap);

the extras_ argument isn't used and the data.getByteArrayExtra gives a nullpointer on backpress of the activity.

Activity

  1. WonderCsabo commented on Nov 16, 2016

    @WonderCsabo
    Member

    Can you post the annotated code?

  2. rickbijkerk commented on Nov 16, 2016

    @rickbijkerk
    Author

    this is the code that should receive the result:

    @OnActivityResult(REQUEST_PICTURE) void onPictureTaken(int resultCode, @OnActivityResult.Extra(value = TakePictureActivity.BITMAP_RESULT_KEY) final byte[] bitmap)

    and this is where i sent it

    Intent intent = new Intent(); intent.putExtra(BITMAP_RESULT_KEY, PhotoService.convertPhotoToJPEG(photo)); setResult(RESULT_OK, intent); finish();

  3. rickbijkerk commented on Nov 16, 2016

    @rickbijkerk
    Author

    this is the currently generated code:
    Bundle extras_ = (((data!= null)&&(data.getExtras()!= null))?data.getExtras():new Bundle()); byte[] bitmap = data.getByteArrayExtra(BITMAPRESULTKEY_EXTRA);

    while i think it should be

    Bundle extras_ = (((data!= null)&&(data.getExtras()!= null))?data.getExtras():new Bundle()); byte[] bitmap = (byte[]) extras_.get(BITMAPRESULTKEY_EXTRA);

    as the extras_ variable bundle is currently unused. Note the cast in the above statement

  4. Zulqurnain commented on Nov 19, 2016

    @Zulqurnain

    i'm facing similar issue , @OnActivityResult annotated method never get's called

  5. Zulqurnain commented on Nov 20, 2016

    @Zulqurnain

    Well i fixed that , by passing 'this' instead of 'context' in Activity_.initent(this).start();

  6. WonderCsabo commented on Nov 23, 2016

    @WonderCsabo
    Member

    @rickbijkerk hmm, we should indeed use the extras_ variable. @dodgex wdyt?

  7. dodgex commented on Nov 23, 2016

    @dodgex
    Member

    @WonderCsabo I think this is a good idea

  8. WonderCsabo commented on Nov 23, 2016

    @WonderCsabo
    Member

    Can you contribute?

  9. dodgex commented on Nov 23, 2016

    @dodgex
    Member

    I'll see what I can do the next days.

  10. self-assigned this
    on Nov 24, 2016
  11. dodgex commented on Nov 24, 2016

    @dodgex
    Member

    I just opened a PR to correct this.

  12. WonderCsabo commented on Nov 24, 2016

    @WonderCsabo
    Member

    Fixed, thanks to @dodgex !

  13. rickbijkerk commented on Dec 2, 2016

    @rickbijkerk
    Author

    looking good thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions