我的名字是约翰,我正在开发这个应用程序,我有 2 种类型的用户,每种类型都有 2 种菜单样式视图。
会发生什么 有时应用程序会崩溃。LogCat 显示“Out of memory on a 11612176-byte allocation”。
这是我在活动之间切换的部分代码:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
getApplicationContext(), R.array.array_teste,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
if (parent.getItemAtPosition(pos).toString().equals("Formador")) {
Intent i = new Intent(getApplicationContext(),
FormadorActivity.class);
finish();
startActivity(i);
}
//
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
我几乎可以肯定我正在使用的图像做错了什么。我希望你们中的一些人能给我一点帮助,我整个星期都在努力解决这个问题。
感谢您的关注!
更新 - -
我正在测试的设备是 Galaxy SII GT-I9100
这是 LogCat :
01-10 16:03:36.243: W/ResourceType(5624): Failure getting entry for 0x010802c0 (t=7 e=704) in package 0 (error -75)
01-10 16:03:37.098: D/dalvikvm(5624): GC_FOR_ALLOC freed 5069K, 45% free 21876K/39175K, paused 32ms, total 32ms
01-10 16:03:37.098: D/AbsListView(5624): [unregisterDoubleTapMotionListener]
01-10 16:03:37.103: I/dalvikvm-heap(5624): Grow heap (frag case) to 26.900MB for 5160976-byte allocation
01-10 16:03:37.153: D/dalvikvm(5624): GC_FOR_ALLOC freed 2K, 32% free 26914K/39175K, paused 48ms, total 48ms
01-10 16:03:37.168: I/MotionRecognitionManager(5624): .unregisterListener : / listener count = 0->0, ubvf 9budiwrd5ordgfl5BakTrklMrfo$,@,*8b-:)(
01-10 16:03:37.213: D/dalvikvm(5624): GC_CONCURRENT freed 67K, 32% free 26848K/39175K, paused 12ms+4ms, total 60ms
01-10 16:03:37.498: D/dalvikvm(5624): GC_FOR_ALLOC freed 112K, 32% free 26735K/39175K, paused 22ms, total 22ms
01-10 16:03:37.498: I/dalvikvm-heap(5624): Forcing collection of SoftReferences for 11612176-byte allocation
01-10 16:03:37.538: D/dalvikvm(5624): GC_BEFORE_OOM freed 0K, 32% free 26735K/39175K, paused 38ms, total 38ms
01-10 16:03:37.538: E/dalvikvm-heap(5624): Out of memory on a 11612176-byte allocation.
01-10 16:03:37.538: I/dalvikvm(5624): "main" prio=5 tid=1 RUNNABLE
01-10 16:03:37.538: I/dalvikvm(5624): | group="main" sCount=0 dsCount=0 obj=0x40d4d508 self=0x40d3c5a8
01-10 16:03:37.538: I/dalvikvm(5624): | sysTid=5624 nice=0 sched=0/0 cgrp=apps handle=1075482416
01-10 16:03:37.538: I/dalvikvm(5624): | schedstat=( 9495706032 3145201445 10530 ) utm=821 stm=128 core=1
01-10 16:03:37.538: I/dalvikvm(5624): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
01-10 16:03:37.548: I/dalvikvm(5624): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:625)
01-10 16:03:37.548: I/dalvikvm(5624): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:478)
01-10 16:03:37.548: I/dalvikvm(5624): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
01-10 16:03:37.548: I/dalvikvm(5624): at android.content.res.Resources.loadDrawable(Resources.java:1963)
01-10 16:03:37.548: I/dalvikvm(5624): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-10 16:03:37.558: I/dalvikvm(5624): at android.widget.ImageView.<init>(ImageView.java:120)
01-10 16:03:37.558: I/dalvikvm(5624): at android.widget.ImageView.<init>(ImageView.java:110)
01-10 16:03:37.558: I/dalvikvm(5624): at java.lang.reflect.Constructor.constructNative(Native Method)
01-10 16:03:37.558: I/dalvikvm(5624): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
01-10 16:03:37.563: I/dalvikvm(5624): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-10 16:03:37.563: I/dalvikvm(5624): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-10 16:03:37.568: I/dalvikvm(5624): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-10 16:03:37.568: I/dalvikvm(5624): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
01-10 16:03:37.568: I/dalvikvm(5624): at android.app.Activity.setContentView(Activity.java:1924)
01-10 16:03:37.573: I/dalvikvm(5624): at com.anfengde.ui.call.FormadorActivity.onCreate(FormadorActivity.java:62)
01-10 16:03:37.573: I/dalvikvm(5624): at android.app.Activity.performCreate(Activity.java:5206)
01-10 16:03:37.573: I/dalvikvm(5624): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-10 16:03:37.573: I/dalvikvm(5624): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
01-10 16:03:37.573: I/dalvikvm(5624): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
01-10 16:03:37.573: I/dalvikvm(5624): at android.app.ActivityThread.access$700(ActivityThread.java:140)
01-10 16:03:37.573: I/dalvikvm(5624): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
01-10 16:03:37.573: I/dalvikvm(5624): at android.os.Handler.dispatchMessage(Handler.java:99)
01-10 16:03:37.573: I/dalvikvm(5624): at android.os.Looper.loop(Looper.java:137)
01-10 16:03:37.573: I/dalvikvm(5624): at android.app.ActivityThread.main(ActivityThread.java:4921)
01-10 16:03:37.573: I/dalvikvm(5624): at java.lang.reflect.Method.invokeNative(Native Method)
01-10 16:03:37.573: I/dalvikvm(5624): at java.lang.reflect.Method.invoke(Method.java:511)
01-10 16:03:37.573: I/dalvikvm(5624): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-10 16:03:37.573: I/dalvikvm(5624): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-10 16:03:37.573: I/dalvikvm(5624): at dalvik.system.NativeStart.main(Native Method)
01-10 16:03:37.578: A/libc(5624): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 5624 (nfengde.ui.call)"
更新 - - - - - - - - - - - - -
这是我认为可能导致错误的代码:
我在 onCreate() 和 onRestart() 上的两个活动上都这样做
settings = getSharedPreferences("MyPreferenceFile", 0);
if (settings.getString("estantePadrao", "teste").equals("Claro")) {
id = getResources().getIdentifier("estante_cursista_v01",
"drawable", getPackageName());
imagemPrateleira.setImageResource(id);
} else {
if (settings.getString("estantePadrao", "teste").equals("Escuro")) {
id = getResources().getIdentifier("estante_cursista_v02",
"drawable", getPackageName());
imagemPrateleira.setImageResource(id);
} else {
id = getResources().getIdentifier("estante_cursista_v03",
"drawable", getPackageName());
imagemPrateleira.setImageResource(id);
}
}