我的应用程序中的其他活动正在正常打开和更改,但是由于某种原因,该活动正在崩溃。知道我的问题是什么吗?

这是课程文件

    package com.gcomcode.oakgang;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

@SuppressWarnings("deprecation")
public class GalleryActivity extends Activity {
private Gallery gallery;

private ImageView imgView;


private Integer[] Imgid = {

        R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4, R.drawable.photo5, R.drawable.photo6, R.drawable.photo7, R.drawable.photo9,

};


@Override

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.gallery_activity);


    imgView = (ImageView)findViewById(R.id.ImageView01);

    imgView.setImageResource(Imgid[0]);


     gallery = (Gallery) findViewById(R.id.examplegallery);

     gallery.setAdapter(new AddImgAdp(this));


     gallery.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

            imgView.setImageResource(Imgid[position]);

        }

    });


}


public class AddImgAdp extends BaseAdapter {

    int GalItemBg;

    private Context cont;


    public AddImgAdp(Context c) {

        cont = c;

        TypedArray typArray = obtainStyledAttributes(R.styleable.Gallery1);

        GalItemBg = typArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);

        typArray.recycle();

    }


    public int getCount() {

        return Imgid.length;

    }


    public Object getItem(int position) {

        return position;

    }


    public long getItemId(int position) {

        return position;

    }


    public View getView(int position, View convertView, ViewGroup parent) {

        ImageView imgView = new ImageView(cont);


        imgView.setImageResource(Imgid[position]);

        imgView.setLayoutParams(new Gallery.LayoutParams(80, 70));

        imgView.setScaleType(ImageView.ScaleType.FIT_XY);

        imgView.setBackgroundResource(GalItemBg);


        return imgView;

    }

}


}


这是对应的.xml

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:id="@+id/LinearLayout01"

android:layout_width="fill_parent" android:layout_height="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical">

<Gallery

    android:id="@+id/examplegallery" android:layout_width="fill_parent"

    android:layout_height="wrap_content" />

<ImageView android:id="@+id/ImageView01"

    android:layout_width="wrap_content" android:layout_height="wrap_content"/>

</LinearLayout>


LogCat错误:

06-29 21:16:47.914:E / AndroidRuntime(22401):致命异常:主
06-29 21:16:47.914:E / AndroidRuntime(22401):进程:com.gcomcode.oakgang,PID:22401
06-29 21:16:47.914:E / AndroidRuntime(22401):java.lang.OutOfMemoryError
06-29 21:16:47.914:E / AndroidRuntime(22401):at android.graphics.BitmapFactory.nativeDecodeAsset(本机方法)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.content.res.Resources.loadDrawable(Resources.java:3024)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.content.res.Resources.getDrawable(Resources.java:1586)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.ImageView.resolveUri(ImageView.java:648)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.ImageView.setImageResource(ImageView.java:377)
06-29 21:16:47.914:E / AndroidRuntime(22401):在com.gcomcode.oakgang.GalleryActivity $ AddImgAdp.getView(GalleryActivity.java:108)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.Gallery.makeAndAddView(Gallery.java:865)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.Gallery.fillToGalleryRightLtr(Gallery.java:819)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.Gallery.fillToGalleryRight(Gallery.java:763)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.Gallery.layout(Gallery.java:672)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.Gallery.onLayout(Gallery.java:357)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.View.layout(View.java:15655)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewGroup.layout(ViewGroup.java:4856)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.View.layout(View.java:15655)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewGroup.layout(ViewGroup.java:4856)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.FrameLayout.onLayout(FrameLayout.java:388)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.View.layout(View.java:15655)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewGroup.layout(ViewGroup.java:4856)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:438)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.View.layout(View.java:15655)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewGroup.layout(ViewGroup.java:4856)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.widget.FrameLayout.onLayout(FrameLayout.java:388)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.View.layout(View.java:15655)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewGroup.layout(ViewGroup.java:4856)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2282)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2002)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1234)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6465)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.Choreographer $ CallbackRecord.run(Choreographer.java:803)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.Choreographer.doCallbacks(Choreographer.java:603)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.Choreographer.doFrame(Choreographer.java:573)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:789)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.os.Handler.handleCallback(Handler.java:733)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.os.Handler.dispatchMessage(Handler.java:95)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.os.Looper.loop(Looper.java:157)
06-29 21:16:47.914:E / AndroidRuntime(22401):位于android.app.ActivityThread.main(ActivityThread.java:5356)
06-29 21:16:47.914:E / AndroidRuntime(22401):at java.lang.reflect.Method.invokeNative(本机方法)
06-29 21:16:47.914:E / AndroidRuntime(22401):at java.lang.reflect.Method.invoke(Method.java:515)
06-29 21:16:47.914:E / AndroidRuntime(22401):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1265)
06-29 21:16:47.914:E / AndroidRuntime(22401):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
06-29 21:16:47.914:E / AndroidRuntime(22401):在dalvik.system.NativeStart.main(本机方法)

最佳答案

这是已知的Android图片问题(功能)。 Google会向您展示有关该主题的大量文章(内存中的Android图像不足)。您可以找到文章android建议如何处理此问题here

10-08 14:15