Опубликовал мою проблему и здесь.
Начинающий ... Я делаю приложение для школьной карты.
Прежде всего у меня есть фон с 4 кнопками (level3, level4, level5, level6).
Я пытаюсь щелкнуть все кнопки, обычно после нажатия 3 из них происходит сбой следующей (каждая кнопка уровня переходит в карту уровня, в результате чего происходит щелчок по изображению комнаты).кнопки, я войду в галерею-переключателя изображений)
У меня есть по крайней мере 5 ImageSwitchers
на картах каждого уровня, так что около 20 ImageSwitcher
галерей в целом.
Я сделал всемои вещи используют Drawable
вместо Bitmap
.У меня есть тонны и тонны изображений (потому что это школьная карта, показывают все фотографии в моей школе, и все эти фоны и ImageButton
)
Я провел некоторые исследования, и те, у кого есть проблемы, - те, кто используетбитовая карта.Некоторые из способов, которые можно решить, это system.gc();
и bitmap.recycle
(хотя я не совсем уверен, как его использовать)
На моем основном фоне - starttour.java
public class StartTour extends Activity {
private SoundManager mSoundManager;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ttour);
mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
mSoundManager.addSound(1, R.raw.beep);
//play music
final MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.jazz);
mPlayer.start();
final Button button = (Button) findViewById(R.id.back);
button.setOnClickListener(new Button.OnClickListener() {
// Implement the OnClickListener callback
public void onClick(View v) {
// do something when the button is clicked
startActivity(new Intent("android.com.Android"));
mSoundManager.playSound(1);
mPlayer.stop();
}
});
final Button button1 = (Button) findViewById(R.id.level3);
button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// Perform action on click
startActivity(new Intent("android.com.Lvl3"));
mSoundManager.playSound(1);
mPlayer.stop();
}
});
final Button button2 = (Button) findViewById(R.id.level4);
button2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// Perform action on click
startActivity(new Intent("android.com.Lvl4"));
mSoundManager.playSound(1);
mPlayer.stop();
}
});
final Button button3 = (Button) findViewById(R.id.level5);
button3.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// Perform action on click
startActivity(new Intent("android.com.Lvl5"));
mSoundManager.playSound(1);
mPlayer.stop();
}
});
final Button button4 = (Button) findViewById(R.id.level6);
button4.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
// Perform action on click
startActivity(new Intent("android.com.Lvl6"));
mSoundManager.playSound(1);
mPlayer.stop();
}
});
}
}
<ImageView android:id="@+id/ilevel4" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="@drawable/level4map"
android:layout_gravity="center"/>
<Button
android:id="@+id/m412button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="92.5px"
android:layout_marginTop="95px"
android:background="@drawable/m412_button" />
<Button
android:id="@+id/m411button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="92.5px"
android:layout_marginTop="248.8px"
android:background="@drawable/m411_button" />
<Button
android:id="@+id/m410button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="92.5px"
android:layout_marginTop="334.8px"
android:background="@drawable/m410_button" />
<Button
android:id="@+id/m405button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6px"
android:layout_marginTop="246.5px"
android:background="@drawable/m405_button" />
<Button
android:id="@+id/m406button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6px"
android:layout_marginTop="335px"
android:background="@drawable/m406_button" />
<Button
android:id="@+id/m419button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="59.5px"
android:background="@drawable/m419_button" />
<Button
android:id="@+id/m420button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="168.5px"
android:background="@drawable/m420_button" />
<Button
android:id="@+id/m421button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="240.5px"
android:background="@drawable/m421_button" />
<Button
android:id="@+id/m422button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="335px"
android:background="@drawable/m422_button" />
</RelativeLayout>
На моем уровне 4.xml
<ImageView android:id="@+id/ilevel4" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="@drawable/level4map"
android:layout_gravity="center"/>
<Button
android:id="@+id/m412button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="92.5px"
android:layout_marginTop="95px"
android:background="@drawable/m412_button" />
<Button
android:id="@+id/m411button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="92.5px"
android:layout_marginTop="248.8px"
android:background="@drawable/m411_button" />
<Button
android:id="@+id/m410button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="92.5px"
android:layout_marginTop="334.8px"
android:background="@drawable/m410_button" />
<Button
android:id="@+id/m405button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6px"
android:layout_marginTop="246.5px"
android:background="@drawable/m405_button" />
<Button
android:id="@+id/m406button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6px"
android:layout_marginTop="335px"
android:background="@drawable/m406_button" />
<Button
android:id="@+id/m419button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="59.5px"
android:background="@drawable/m419_button" />
<Button
android:id="@+id/m420button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="168.5px"
android:background="@drawable/m420_button" />
<Button
android:id="@+id/m421button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="240.5px"
android:background="@drawable/m421_button" />
<Button
android:id="@+id/m422button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260px"
android:layout_marginTop="335px"
android:background="@drawable/m422_button" />
</RelativeLayout>
На уровне4.java
public class Level4 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tlevel4);
final Button button1 = (Button) findViewById(R.id.m405button);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on click
startActivity(new Intent("android.com.M405"));
}
});
final Button button2 = (Button) findViewById(R.id.m406button);
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on click
startActivity(new Intent("android.com.M406"));
}
});
}
}
Вlogcat
11-03 12:35:55.194: ERROR/dalvikvm-heap(708): 483406-byte external allocation too large for this process.
11-03 12:35:55.194: ERROR/(708): VM won't let us allocate 483406 bytes
11-03 12:35:55.204: DEBUG/AndroidRuntime(708): Shutting down VM
11-03 12:35:55.213: WARN/dalvikvm(708): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
11-03 12:35:55.213: ERROR/AndroidRuntime(708): Uncaught handler: thread main exiting due to uncaught exception
11-03 12:35:55.254: ERROR/AndroidRuntime(708): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.com/android.com.Level3}: android.view.InflateException: Binary XML file line #7: Error inflating class java.lang.reflect.Constructor
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.os.Looper.loop(Looper.java:123)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.ActivityThread.main(ActivityThread.java:3948)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at java.lang.reflect.Method.invoke(Method.java:521)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at dalvik.system.NativeStart.main(Native Method)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class java.lang.reflect.Constructor
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.Activity.setContentView(Activity.java:1626)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.com.Level3.onCreate(Level3.java:19)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): ... 11 more
11-03 12:35:55.254: ERROR/AndroidRuntime(708): Caused by: java.lang.reflect.InvocationTargetException
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.widget.ImageView.<init>(ImageView.java:103)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at java.lang.reflect.Constructor.constructNative(Native Method)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): ... 22 more
11-03 12:35:55.254: ERROR/AndroidRuntime(708): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:363)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:212)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:663)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.content.res.Resources.loadDrawable(Resources.java:1637)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): at android.widget.ImageView.<init>(ImageView.java:113)
11-03 12:35:55.254: ERROR/AndroidRuntime(708): ... 26 more
Если я сначала нажму на любую из кнопок и войду в карту уровней, произойдет сбой при просмотре изображений переключателя изображений.
В logcat
11-03 09:17:34.308: INFO/ActivityManager(564): Starting activity: Intent { action=android.com.M615 comp={android.com/android.com.M615_gallery} }
11-03 09:17:34.638: ERROR/dalvikvm-heap(712): 212800-byte external allocation too large for this process.
11-03 09:17:34.638: ERROR/(712): VM won't let us allocate 212800 bytes
11-03 09:17:34.638: DEBUG/AndroidRuntime(712): Shutting down VM
11-03 09:17:34.648: WARN/dalvikvm(712): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
11-03 09:17:34.648: ERROR/AndroidRuntime(712): Uncaught handler: thread main exiting due to uncaught exception
11-03 09:17:34.677: ERROR/AndroidRuntime(712): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:363)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:212)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:663)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.content.res.Resources.loadDrawable(Resources.java:1637)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.content.res.Resources.getDrawable(Resources.java:535)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.ImageView.resolveUri(ImageView.java:482)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.ImageView.setImageResource(ImageView.java:268)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.com.M615_gallery$AddImgAdp.getView(M615_gallery.java:71)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.Gallery.makeAndAddView(Gallery.java:754)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.Gallery.fillToGalleryRight(Gallery.java:703)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.Gallery.layout(Gallery.java:634)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.Gallery.onLayout(Gallery.java:339)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.view.View.layout(View.java:6133)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.view.View.layout(View.java:6133)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.view.View.layout(View.java:6133)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.view.View.layout(View.java:6133)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.view.View.layout(View.java:6133)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.view.ViewRoot.performTraversals(ViewRoot.java:929)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.view.ViewRoot.handleMessage(ViewRoot.java:1482)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.os.Looper.loop(Looper.java:123)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at android.app.ActivityThread.main(ActivityThread.java:3948)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at java.lang.reflect.Method.invoke(Method.java:521)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
11-03 09:17:34.677: ERROR/AndroidRuntime(712): at dalvik.system.NativeStart.main(Native Method)
действительно очень ценю, если кто-то может помочь .. спасибо
PS: у меня есть тонны изображений в приложении.У меня есть как минимум 5 ImageSwitcher
галерей на каждом уровне, так что в моем приложении можно добавить до 20 переключателей изображений.