任何人都可以解释一下这个问题是什么,并告诉我解决方案是什么? 我的应用使用了一个列表视图,可以在其中充气并显示图像。图像非常小,只有几kbs(每个小于20 kbs)....有些视图在列表中只有一个或两个图像,但有些图像最多有12个图像。
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
at android.content.res.Resources.loadDrawable(Resources.java:3022)
at android.content.res.Resources.getDrawable(Resources.java:1586)
at android.widget.ImageView.resolveUri(ImageView.java:648)
at android.widget.ImageView.setImageResource(ImageView.java:377)
at com.admads.android.HisnulMuslim_Google_JQM.DuaAdapter.getView(DuaAdapter.java:78)
at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:230)
at android.widget.AbsListView.obtainView(AbsListView.java:2707)
at android.widget.ListView.makeAndAddView(ListView.java:1801)
at android.widget.ListView.fillDown(ListView.java:697)
at android.widget.ListView.fillGap(ListView.java:661)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:6651)
at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3916)
at android.widget.AbsListView.onTouchMove(AbsListView.java:4756)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:4582)
at android.view.View.dispatchTouchEvent(View.java:8093)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2405)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2129)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2411)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2144)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2252)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1587)
at android.app.Activity.dispatchTouchEvent(Activity.java:2507)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2200)
at android.view.View.dispatchPointerEvent(View.java:8301)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4531)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4403)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3961)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4015)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3984)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4095)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3992)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4152)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3961)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4015)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3984)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3992)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3961)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6320)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6222)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6193)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6158)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6400)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6373)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6419)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:571)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5293)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
主要活动代码[主要部分]
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getApplicationContext();
setContentView(R.layout.myact);
getActionBar().setDisplayHomeAsUpEnabled(true);
final DataBaseHelper db = new DataBaseHelper(context);
try {db.createDataBase();} catch (IOException e) {e.printStackTrace();}
db.openDataBase();
if (savedInstanceState == null) { }
cd = db.getDetsById(iid);
dualist = (ListView) findViewById(R.id.dua_list);
prepareList();
getActionBar().setDisplayHomeAsUpEnabled(true);
mAdapter1 = new DuaAdapter(getApplicationContext(),duaItems);
dualist.setAdapter(mAdapter1);
db.close();
prevbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
currentDua--;
Intent intent = getIntent();
intent.putExtra("iid", currentDua);
finish();startActivity(intent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}
});
nxtbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
currentDua++;
Intent intent = getIntent();
intent.putExtra("iid", currentDua);
finish();
startActivity(intent);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
public void prepareList() {
duaItems = new ArrayList<DuaItem>();
cd.moveToFirst();
do {
duaItems.add(new DuaItem(isTopV, cd.getString(1), isImgV, cd.getString(2), isAudV, cd.getString(3),isTransV, cd.getString(4), isTranslitV, cd.getString(5)));
} while (cd.moveToNext());
}
适配器类[主要部分]
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.list_item_dua, null);
}
TextView textViewTop = (TextView) convertView.findViewById(R.id.textViewTop);
ImageView imageViewDua = (ImageView) convertView.findViewById(R.id.imageViewDua);
final Button btnPP = (Button) convertView.findViewById(R.id.playpause);
TextView txtViewTranslation = (TextView) convertView.findViewById(R.id.txtViewTranslation);
TextView txtViewTransliteration = (TextView) convertView.findViewById(R.id.txtViewTransliteration);
textViewTop.setText(Html.fromHtml(duaItems.get(position).getTop()));
int resId = context.getResources().getIdentifier(duaItems.get(position).getImage(), "drawable", context.getPackageName());
imageViewDua.setImageResource(resId);
txtViewTranslation.setText(t1);
txtViewTransliteration.setText(t2);
final int audId = context.getResources().getIdentifier(duaItems.get(position).getAudio(), "raw",context.getPackageName());
btnPP.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(mPlayer.isPlaying()) {
mPlayer.reset(); btnPP.setText("c");
} else {
mPlayer.release(); mPlayer = MediaPlayer.create(context, audId);
//try { mPlayer.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
mPlayer.start(); btnPP.setText("a");
mPlayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) {
mPlayer.reset(); mPlayer.release(); btnPP.setText("c");}
});
}
}
});
return convertView;
}
}