我的应用得到了很多的崩溃报告
当onClickListener被调用应用程序崩溃。仅适用于Android版本7.0和7.1都受到影响。我已经尝试启动应用程序上与Android版本7,但在模拟器上的一切工作正常一个仿真器。
这是崩溃报告:
java.lang.OutOfMemoryError:
at dalvik.system.VMRuntime.newNonMovableArray (Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset (Native Method)
at android.graphics.BitmapFactory.decodeStream (BitmapFactory.java:655)
at android.graphics.BitmapFactory.decodeResourceStream (BitmapFactory.java:483)
at android.graphics.drawable.Drawable.createFromResourceStream (Drawable.java:1157)
at android.content.res.ResourcesImpl.loadDrawableForCookie (ResourcesImpl.java:720)
at android.content.res.ResourcesImpl.loadDrawable (ResourcesImpl.java:571)
at android.content.res.Resources.getDrawable (Resources.java:889)
at android.content.Context.getDrawable (Context.java:530)
at android.support.v4.content.ContextCompat.getDrawable (ContextCompat.java:351)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:200)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable (AppCompatDrawableManager.java:188)
at android.support.v7.content.res.AppCompatResources.getDrawable (AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.setImageResource (AppCompatImageHelper.java:85)
at android.support.v7.widget.AppCompatImageView.setImageResource (AppCompatImageView.java:94)
at com.future.king.johncena.tabs.Tab1$1.onClick (Tab1.java:94)
at android.view.View.performClick (View.java:5675)
at android.view.View$PerformClick.run (View.java:22641)
at android.os.Handler.handleCallback (Handler.java:836)
at android.os.Handler.dispatchMessage (Handler.java:103)
at android.os.Looper.loop (Looper.java:203)
at android.app.ActivityThread.main (ActivityThread.java:6251)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:924)
这是我的onClickListener:
public void button() {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cleanUpMediaPlayer();
mp = MediaPlayer.create(getActivity(), R.raw.sound);
mp.start();
if(!sound1){
mp.setVolume(0.0f, 0.0f);
}
button.setImageResource(R.drawable.button1);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
button.setImageResource(R.drawable.button);
}
});
}
});
}
94号线
button.setImageResource(R.drawable.button1);
我希望有人能告诉我是什么导致了这种崩溃。
我会强烈建议使用selector
状态可绘为button
并更改按键的状态,而不是在onClick
方法设置图像资源。
见State List documentation以供参考。