0

I have made an android application,And I am stuck at the point as it gives me an exception,That I am not getting,The Exception is about permission,I have tried to write this permission to manifest file to but its not working,My Exception is as below: code

if(selectPhotoCountryActivity.picturePath2 != null && selectPhotoCountryActivity.picturePath2 !="" )
        {
        //  yourBitmap = BitmapFactory.decodeFile(selectPhotoMainActivity.picturePath);


             try
             {
                 yourBitmap = BitmapFactory.decodeFile(selectPhotoCountryActivity.picturePath2);
                  resized = Bitmap.createScaledBitmap(yourBitmap, 200, 300, true);
                 imageView4Photo = new ImageView(this);
                 frm_v.destroyDrawingCache();

                 imageView3Frame = new ImageView(this);
                 imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.img_back_frm));
                // imageView5 = new ImageView(this);
            //   imageView5.setImageDrawable(getResources().getDrawable(R.drawable.secondscimgbgwithshadow));
                  //as
                /* if(imageView3 == null)
                 {
                     imageView3.setImageDrawable(getResources().getDrawable(R.drawable.fram2));
                 }*/
                 if(imageView3Frame.getDrawable() != null)
                 {
                     width = imageView3Frame.getDrawable().getMinimumWidth();//+80;
                     height = imageView3Frame.getDrawable().getMinimumHeight();//+80;
                     //image_view3.getLayoutParams().height = 250;
                     Log.e("test ","is i3 is not null");
                 }

                 Resources resources = this.getResources();
                 DisplayMetrics metrics = resources.getDisplayMetrics();
                 if (width > metrics.widthPixels)
                 {
                     width = metrics.widthPixels;//+80;
                     height = width * height / imageView3Frame.getDrawable().getMinimumWidth();//+80;
                     Log.e("test ","is i3 is not null  width > metrics.w....");
                 }

                 frm_v.removeAllViews();
                  //  imageView5.
                 int width1=230,height1=200;
               //  LayoutParams params2=new LayoutParams(width1, height1);
                 LayoutParams params=new LayoutParams(width, height);

               //  LayoutParams param=new LayoutParams(300, 300);
                 //imageView3.
                 frm_v.addView(imageView3Frame, params);
               //  frm_v.addView(imageView4Photo,params);
                 FrameLayout.LayoutParams paramss = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER);

                 ((FrameLayout) findViewById(R.id.frm_layout_photo_frame)).addView(imageView4Photo, paramss);

             //    frm_v.addView(imageView5,params);
                 imageView4Photo.setImageBitmap(resized);
                 //imageView4.setOnTouchListener(new Touch(SetPhotoFrameActivity.this));
                 imageView4Photo.setVisibility(View.GONE);
                 imageView3Frame.bringToFront();
                 imageView4Photo.setVisibility(View.VISIBLE);
             }
             catch (Exception e)
             {
                 e.printStackTrace();
             }

        if(SelectPhotoCountryActivity.countryName2 != null && SelectPhotoCountryActivity.countryName2 !="" )
        {

             //SelectPhotoCountryActivity.countryName2;
             try
             {

                 if(SelectPhotoCountryActivity.countryName2.equals("USA"))
                    {
                        Log.i("select frame of","USA");
                        //imageView32 = new ImageView(this);
                        imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.usa_frame));

                    }
                /*else if(SelectPhotoCountryActivity.countryName2.equals("USA"))
                {
                    Log.i("select frame of","USA");
                    //imageView32 = new ImageView(this);
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.usa_frame));

                }*/
                else if (SelectPhotoCountryActivity.countryName2.equals("Algeria")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.algeria));                   
                }//2
                else if (SelectPhotoCountryActivity.countryName2.equals("Cameroon")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.camerron));                  
                }//3
                else if (SelectPhotoCountryActivity.countryName2.equals("Côte d`Ivoire")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.cotedlvorie));                   
                }//4

                else if (SelectPhotoCountryActivity.countryName2.equals("Ghana")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.ghana));                 
                }//5 
                else if (SelectPhotoCountryActivity.countryName2.equals("Nigeria")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.nigeria));                   
                }//6

                else if (SelectPhotoCountryActivity.countryName2.equals("Australia")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.australia));                 
                }//7
                else if (SelectPhotoCountryActivity.countryName2.equals("Iran")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.iran));                  
                }//8 remain

                else if (SelectPhotoCountryActivity.countryName2.equals("Japan")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.japan));                 
                }//9
                else if (SelectPhotoCountryActivity.countryName2.equals("Korea Republic")) 
                {
                    imageView3Frame.setImageDrawable(getResources().getDrawable(R.drawable.korearepublic));                 
                }//10
                else if (SelectPhotoCountryActivity.countryName2.equals("Belgium")) 
                {

log.txt

  06-12 12:00:21.285: E/AndroidRuntime(18813): FATAL EXCEPTION: main
06-12 12:00:21.285: E/AndroidRuntime(18813): java.lang.OutOfMemoryError
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:586)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:439)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.content.res.Resources.loadDrawable(Resources.java:2988)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.content.res.Resources.getDrawable(Resources.java:1558)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at com.example.footballapp.SetPhotoFrameActivity.buttonClickEvents(SetPhotoFrameActivity.java:371)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at com.example.footballapp.SetPhotoFrameActivity.onCreate(SetPhotoFrameActivity.java:197)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.app.Activity.performCreate(Activity.java:5372)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.app.ActivityThread.access$700(ActivityThread.java:168)
06-12 12:00:21.285: E/AndroidRuntime(18813):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
jigar
  • 23
  • 1
  • 11
  • try adding permission android.permission.INTERACT_ACROSS_USERS_FULL in your manifest file – silwar Jun 12 '14 at 06:26
  • @silwar-Please see edits...thank you – jigar Jun 12 '14 at 06:31
  • If your question is actually about memory, have you tried to use a [large heap size](http://stackoverflow.com/questions/11275650/how-to-increase-heap-size-of-an-android-application)? – ChiefTwoPencils Jun 12 '14 at 06:34

2 Answers2

0
// Try to use this method instead of BitmapFactory.decodeFile(path)

private Uri getImageUri(String path) {
    return Uri.fromFile(new File(path));
}

private Bitmap decodeFileFromPath(String path){
        Uri uri = getImageUri(path);
        InputStream in = null;
        try {
            in = getContentResolver().openInputStream(uri);

            //Decode image size
            BitmapFactory.Options o = new BitmapFactory.Options();
            o.inJustDecodeBounds = true;

            BitmapFactory.decodeStream(in, null, o);
            in.close();


            int scale = 1;
            int inSampleSize = 1024;
            if (o.outHeight > inSampleSize || o.outWidth > inSampleSize) {
                scale = (int) Math.pow(2, (int) Math.round(Math.log(inSampleSize / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
            }

            BitmapFactory.Options o2 = new BitmapFactory.Options();
            o2.inSampleSize = scale;
            in = getContentResolver().openInputStream(uri);
            Bitmap b = BitmapFactory.decodeStream(in, null, o2);
            in.close();

            return b;

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
Haresh Chhelana
  • 23,930
  • 5
  • 51
  • 66
0

The error is caused while decoding the asset so try some of these options for deco

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
options.inJustDecodeBounds = true;

yourBitmap = BitmapFactory.decodeFile(selectPhotoCountryActivity.picturePath2, options);
resized = Bitmap.createScaledBitmap(yourBitmap, 200, 300, true);

or some of these settings also

BitmapFactory.Options options;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Config.RGB_565;
options.inDither = true;
Girish Nair
  • 4,958
  • 4
  • 38
  • 61