-2

I know how to pickUp Image from the gallery.But the same code is work in my other Application But in my new Application is does not work.

public class RegisterActivity extends AppCompatActivity{

    Button upload_proof_button;

    Bitmap bitmaps;
    private static final int PICK_IMAGE = 100;
    ImageView filename;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        filename = (ImageView) findViewById(R.id.filename_textveiw);

        upload_proof_button = (Button)findViewById(R.id.upload_proof_button);
        upload_proof_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent gallery =  new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
                startActivityForResult(gallery, PICK_IMAGE);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK && requestCode == PICK_IMAGE) {
            Uri imageUri = data.getData();

            try {
                bitmaps = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);

                if(bitmaps == null){
                    filename.setImageBitmap(bitmaps);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

}

and I write permission in manifest.xml file.

  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Error Logcat :

07-20 06:16:10.401 12940-12940/com.example.softeng.jogifinal D/dalvikvm: GC_FOR_ALLOC freed 287K, 13% free 3182K/3640K, paused 2ms, total 2ms 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal W/dalvikvm: VFY: unable to resolve virtual method 442: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal W/dalvikvm: VFY: unable to resolve virtual method 444: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal W/dalvikvm: VFY: unable to resolve instanceof 152 (Landroid/graphics/drawable/RippleDrawable;) in Landroid/support/v7/widget/AppCompatImageHelper; 07-20 06:16:10.411 12940-12940/com.example.softeng.jogifinal D/dalvikvm: VFY: replacing opcode 0x20 at 0x000c 07-20 06:16:10.721 12940-12940/com.example.softeng.jogifinal D/OpenGLRenderer: Enabling debug mode 0 07-20 06:16:14.441 12940-12940/com.example.softeng.jogifinal I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList 07-20 06:16:14.441 12940-12940/com.example.softeng.jogifinal W/dalvikvm: VFY: unable to resolve virtual method 287: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList; 07-20 06:16:14.441 12940-12940/com.example.softeng.jogifinal D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006 07-20 06:16:15.731 12940-12940/com.example.softeng.jogifinal D/dalvikvm: GC_FOR_ALLOC freed 270K, 12% free 3281K/3724K, paused 3ms, total 3ms 07-20 06:16:15.741 12940-12940/com.example.softeng.jogifinal D/dalvikvm: GC_FOR_ALLOC freed 97K, 14% free 3337K/3880K, paused 1ms, total 2ms 07-20 06:16:15.741 12940-12940/com.example.softeng.jogifinal I/dalvikvm-heap: Grow heap (frag case) to 5.106MB for 1764372-byte allocation 07-20 06:16:15.751 12940-12948/com.example.softeng.jogifinal D/dalvikvm: GC_FOR_ALLOC freed <1K, 10% free 5060K/5604K, paused 5ms, total 5ms

What I have do :

  1. try to clean the project.
  2. try Invalidate and caches.
  3. Restart Andriod Studio 3 time. But not work..

Any Help be Appreciated ..

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95

1 Answers1

0

You check if your bitmap is null to set it to the ImageView. Change to this :

if (bitmaps != null) {
    filename.setImageBitmap(bitmaps);
} else {
    filename.setImageResource(R.drawable.default_image);
}
Lubomir Babev
  • 1,892
  • 1
  • 12
  • 14