Android 画廊活动崩溃?
我的应用程序中的其他活动正在打开和更改,但由于某些原因,这一活动正在崩溃。知道我的问题是什么吗 这是类文件Android 画廊活动崩溃?,android,xml,android-activity,Android,Xml,Android Activity,我的应用程序中的其他活动正在打开和更改,但由于某些原因,这一活动正在崩溃。知道我的问题是什么吗 这是类文件 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 an
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;
}
}
}
package com.gcomcode.oakgang;
导入android.app.Activity;
导入android.content.Context;
导入android.content.res.TypedArray;
导入android.os.Bundle;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemClickListener;
导入android.widget.BaseAdapter;
导入android.widget.Gallery;
导入android.widget.ImageView;
@抑制警告(“弃用”)
公共类GalleryActivity扩展了活动{
私人画廊;
私有图像视图imgView;
私有整数[]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,
};
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_活动);
imgView=(ImageView)findViewById(R.id.ImageView01);
imgView.setImageResource(Imgid[0]);
gallery=(gallery)findViewById(R.id.examplegallery);
gallery.setAdapter(新AddImgAdp(本));
gallery.setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父视图、视图v、整型位置、长id){
imgView.setImageResource(Imgid[position]);
}
});
}
公共类addimgapp扩展BaseAdapter{
int GalItemBg;
私人语境控制;
公共AddImgAdp(上下文c){
cont=c;
TypedArray typArray=获得的StyledAttributes(R.styleable.Gallery1);
GalItemBg=typArray.getResourceId(R.styleable.Gallery1\u android\u galleryItemBackground,0);
typArray.recycle();
}
public int getCount(){
返回Imgid.length;
}
公共对象getItem(int位置){
返回位置;
}
公共长getItemId(int位置){
返回位置;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
ImageView imgView=新的ImageView(续);
imgView.setImageResource(Imgid[position]);
imgView.setLayoutParams(新图库.LayoutParams(80,70));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(GalItemBg);
返回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):在android.graphics.BitmapFactory.NativeDeacSet(本机方法)
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$addimgapp.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)上
android:largeHeap="true"