Autore Topic: Problema con Gallery e immagini caricate  (Letto 429 volte)

Offline simox2601

  • Nuovo arrivato
  • *
  • Post: 30
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    Galaxy S4
  • Sistema operativo:
    Windows
Problema con Gallery e immagini caricate
« il: 08 Novembre 2013, 11:40:01 CET »
0
Ciao a tutti :)

Nell'app che sto facendo ho bisogno di una piccola galleria di immagini. L'activity riceve da quella precedente un id ed a seconda dell'id carica le immagini corrispondenti (generalmente 3). Inizialmente avevo inserito 3 immagini casuali da pochi kb poi ho inserito le originali che sono intorno ai 100-300kb.

Caricandole ho questo errore :
Codice: [Seleziona]
11-08 11:30:15.314: E/AndroidRuntime(2648): FATAL EXCEPTION: main
11-08 11:30:15.314: E/AndroidRuntime(2648): java.lang.OutOfMemoryError
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:817)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.content.res.Resources.loadDrawable(Resources.java:2854)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.content.res.Resources.getDrawable(Resources.java:1521)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.ImageView.resolveUri(ImageView.java:628)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.ImageView.setImageResource(ImageView.java:361)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at cmd.sva.Activity.RegDaySingleDishActivity$ImageAdapter.getView(RegDaySingleDishActivity.java:277)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.Gallery.makeAndAddView(Gallery.java:865)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:819)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.Gallery.fillToGalleryRight(Gallery.java:763)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.Gallery.trackMotionScroll(Gallery.java:393)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.Gallery.onScroll(Gallery.java:1043)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.GestureDetector.onTouchEvent(GestureDetector.java:1377)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.widget.Gallery.onTouchEvent(Gallery.java:958)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.View.dispatchTouchEvent(View.java:7462)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2264)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1995)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2270)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2010)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2182)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1512)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2130)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.View.dispatchPointerEvent(View.java:7642)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3682)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3613)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4804)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4783)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4875)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:174)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4854)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4894)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.Choreographer.doFrame(Choreographer.java:530)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.os.Handler.handleCallback(Handler.java:725)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.os.Handler.dispatchMessage(Handler.java:92)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.os.Looper.loop(Looper.java:137)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at android.app.ActivityThread.main(ActivityThread.java:5328)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at java.lang.reflect.Method.invokeNative(Native Method)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at java.lang.reflect.Method.invoke(Method.java:511)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
11-08 11:30:15.314: E/AndroidRuntime(2648):         at com.android.internal.os.ZygoteInit.main(

Il codice che utilizzo per la visualizzazione delle immagini è questo:
Codice (Java): [Seleziona]
public class ImageAdapter extends BaseAdapter {
            int mGalleryItemBackground;
            private Context mContext;
           
            String pkg=getPackageName();
        Intent intent = getIntent();
            String id = intent.getStringExtra(pkg+".myInt");
                   
            String B = "b" + id.substring(1);
            String D = "d" + id.substring(1);
            String F = "f" + id.substring(1);
           
            private Integer[] mImageIds = {
                        getResources().getIdentifier(B, "drawable", "cmd.sva"),
                        getResources().getIdentifier(D, "drawable", "cmd.sva"),
                        getResources().getIdentifier(F, "drawable", "cmd.sva"),
            };
           
           
            public ImageAdapter(Context c) {
                mContext = c;
            }
         
            public int getCount() {
                return mImageIds.length;
            }
         
            public java.lang.Object getItem(int position) {
                return position;
            }
         
            public long getItemId(int position) {
                return position;
            }
         
            @Override
            public View getView(int arg0, View arg1, ViewGroup arg2) {
                ImageView iv = new ImageView(mContext);
                iv.setImageResource(mImageIds[arg0]);
                iv.setScaleType(ImageView.ScaleType.FIT_XY);
                iv.setLayoutParams(new Gallery.LayoutParams(400,320));
                return iv;
            }
        }

e viene nel main:
Codice (Java): [Seleziona]
final Gallery gallery = (Gallery) findViewById(R.id.image);
        gallery.setSpacing(1);
        gallery.setAdapter(new ImageAdapter(this));

Come posso risolvere???

Grazie in anticipo