0

Log :

03-29 06:14:23.526: I/Choreographer(8792): Skipped 140 frames!  The application may be doing too much work on its main thread.
03-29 06:14:24.826: D/Response:(8792): > [{"MyImage":[47,57,106,47,52,65,65,81,83,107,90,74,82,103,65,66,65,81,65,65,65,81,65,66,65,65,68,47,50,119],"RegID":15,"TotFriends":4,"TotLosses":3,"TotWins":0}]
03-29 06:14:24.826: D/Hi(8792): or bandar
03-29 06:14:24.846: D/len(8792): 1
03-29 06:14:24.877: D/>>>(8792): [47,57,106,47,52,65,65,81,83,107,90,74,82,103,65,66,65,81,65,65,65,81,65,66,65,65,68,47,50,119]
03-29 06:14:25.117: D/dalvikvm(8792): GC_FOR_ALLOC freed 1031K, 29% free 4040K/5616K, paused 179ms, total 203ms
03-29 06:14:25.117: I/dalvikvm-heap(8792): Forcing collection of SoftReferences for 185326656-byte allocation
03-29 06:14:25.396: D/dalvikvm(8792): GC_BEFORE_OOM freed 13K, 29% free 4027K/5616K, paused 243ms, total 279ms
03-29 06:14:25.396: E/dalvikvm-heap(8792): Out of memory on a 185326656-byte allocation.
03-29 06:14:25.406: I/dalvikvm(8792): "main" prio=5 tid=1 RUNNABLE
03-29 06:14:25.406: I/dalvikvm(8792):   | group="main" sCount=0 dsCount=0 obj=0x414c5578 self=0x2a00d090
03-29 06:14:25.406: I/dalvikvm(8792):   | sysTid=8792 nice=0 sched=0/0 cgrp=apps handle=1073811452
03-29 06:14:25.416: I/dalvikvm(8792):   | state=R schedstat=( 11010907622 17481370015 17046 ) utm=929 stm=172 core=0
03-29 06:14:25.416: I/dalvikvm(8792):   at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
03-29 06:14:25.436: I/dalvikvm(8792):   at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:429)
03-29 06:14:25.436: I/dalvikvm(8792):   at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:447)
03-29 06:14:25.436: I/dalvikvm(8792):   at com.example.buddybets.MyProfile.onCreate(MyProfile.java:142)
03-29 06:14:25.436: I/dalvikvm(8792):   at android.app.Activity.performCreate(Activity.java:5133)
03-29 06:14:25.436: I/dalvikvm(8792):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 06:14:25.436: I/dalvikvm(8792):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-29 06:14:25.447: I/dalvikvm(8792):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-29 06:14:25.447: I/dalvikvm(8792):   at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-29 06:14:25.457: I/dalvikvm(8792):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-29 06:14:25.457: I/dalvikvm(8792):   at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 06:14:25.466: I/dalvikvm(8792):   at android.os.Looper.loop(Looper.java:137)
03-29 06:14:25.466: I/dalvikvm(8792):   at android.app.ActivityThread.main(ActivityThread.java:5103)
03-29 06:14:25.466: I/dalvikvm(8792):   at java.lang.reflect.Method.invokeNative(Native Method)
03-29 06:14:25.476: I/dalvikvm(8792):   at java.lang.reflect.Method.invoke(Method.java:525)
03-29 06:14:25.476: I/dalvikvm(8792):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-29 06:14:25.476: I/dalvikvm(8792):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-29 06:14:25.486: I/dalvikvm(8792):   at dalvik.system.NativeStart.main(Native Method)
03-29 06:14:25.497: D/skia(8792): --- decoder->decode returned false
03-29 06:14:25.497: D/AndroidRuntime(8792): Shutting down VM
03-29 06:14:25.506: W/dalvikvm(8792): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
03-29 06:14:25.647: E/AndroidRuntime(8792): FATAL EXCEPTION: main
03-29 06:14:25.647: E/AndroidRuntime(8792): java.lang.OutOfMemoryError
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:429)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:447)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at com.example.buddybets.MyProfile.onCreate(MyProfile.java:142)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.app.Activity.performCreate(Activity.java:5133)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.os.Looper.loop(Looper.java:137)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at android.app.ActivityThread.main(ActivityThread.java:5103)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at java.lang.reflect.Method.invokeNative(Native Method)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at java.lang.reflect.Method.invoke(Method.java:525)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-29 06:14:25.647: E/AndroidRuntime(8792):     at dalvik.system.NativeStart.main(Native Method)
03-29 06:17:06.707: I/Process(8792): Sending signal. PID: 8792 SIG: 9
03-29 06:17:08.657: I/Choreographer(9176): Skipped 179 frames!  The application may be doing too much work on its main thread.
Benoît Guédas
  • 801
  • 7
  • 25
Parvindra Singh
  • 53
  • 2
  • 10
  • Please ans me if any one knows... i putting image as base 64 string successfully on server but when retrive same in another class for setting on image view "Out Of Memory" occruss :-( – Parvindra Singh Mar 29 '14 at 10:53
  • 1
    Possible of duplicate http://stackoverflow.com/questions/15756221/android-bitmap-memory-issue-error-out-of-memory-on-a-8294416-byte-allocation – Piyush Mar 29 '14 at 10:55
  • you must resize bitmap before converting Base64 – Imtiyaz Khalani Mar 29 '14 at 10:59
  • I resized bitmap..as Bitmap bm = BitmapFactory.decodeStream(fis); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bm.compress(CompressFormat.JPEG,40, stream); String imgString = Base64.encodeToString( stream.toByteArray(), Base64.NO_WRAP); bm.recycle(); – Parvindra Singh Mar 29 '14 at 11:13
  • [47,57,106,47,52,65,65,81,83,107,90,74,82,103,65,66,65,81,65,65,65,81,65,66,65,65,68,47,50,119] this the byte array i retrived that i put as base 64 string in remote database.. why i retrive too small array.. i think there is some problem – Parvindra Singh Mar 29 '14 at 11:19

3 Answers3

0

Read following tutorial:

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

You can try following code

set width as a layout width or screen width;

find screen width:

 DisplayMetrics displaymetrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
  int height = displaymetrics.heightPixels;
  int width = displaymetrics.widthPixels;
  Drawable drawable = new BitmapDrawable(getResources(), decodeFile(chkFile, width , height )); 
                                imageView.setBackground(drawable);


public  Bitmap decodeFile(File f,int WIDTH,int HIGHT){
         try {
             //Decode image size
             BitmapFactory.Options o = new BitmapFactory.Options();
             o.inJustDecodeBounds = true;
             BitmapFactory.decodeStream(new FileInputStream(f),null,o);

             //The new size we want to scale to
             final int REQUIRED_WIDTH=WIDTH;
             final int REQUIRED_HIGHT=HIGHT;
             //Find the correct scale value. It should be the power of 2.
             int scale=1;
             while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
                 scale*=2;

             //Decode with inSampleSize
             BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=scale;
             return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
         } catch (FileNotFoundException e) {
             System.out.println("bitmap decodeFile:"+e);
         }
         return null;
        }
Hemantvc
  • 2,111
  • 3
  • 30
  • 42
0

Just put largeHeap="true" to your application tag (AndroidManifest.xml)

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true" >

Hope it will help you. Thank you.

Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
0

The server is sending you a base 64 string, and you're trying to read its bytes directly. You first need to decode it and then convert to a byte array.

Try this:

byte[] decodedBytes = Base64.decode(pic, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodedBytes ,0,decodedBytes.length)
ZygoteInit
  • 485
  • 6
  • 9