我的名字是John,我正在开发这个应用程序,我有两种类型的用户,每种类型都有2个菜单样式视图。
有时应用程序崩溃会发生什么事。 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);
}
}
答案 0 :(得分:0)
我发现我手机中安装的ROM内存泄漏导致应用程序崩溃。
我已经在其他设备上测试过它正常工作。
感谢所有的帮助和支持!