1
我的名字是約翰,我正在開發此應用程序,我有2種類型的用戶,每種類型都有2個菜單樣式視圖。Android應用程序內存不足錯誤更改時活動
發生了什麼它有時會導致應用程序崩潰。 LogCat顯示「11612176字節分配內存不足」。
這裏就是我的活動之間進行切換的部分代碼:
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);
}
}
歡迎來到StackOverflow。哪一行出現異常?圖像的尺寸是什麼?未壓縮的尺寸爲11.6 MB,這對於手持設備上的顯示器聽起來非常大。該設備有多少內存? –
您是否想要在該活動中加載大量圖像?如果你能解釋更多的話,這將是非常棒的...粘貼整個logcat信息,這也將幫助我們確定問題 –
感謝您的關注,我已經使用Device和LogCat更新了帖子。希望你能給我一些幫助。對不起身份不好。 – DallaRosa