安卓新人求指教,程序执行到一半就自动退出了?什么原因

sinat_32165885 2015-11-14 06:58:18
为什么程序执行到一般就关闭了?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:textOn="开"
android:textOff="关"
/>

<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toggleButton1"
android:layout_centerHorizontal="true"
android:src="@drawable/of" />

</RelativeLayout>
package com.example.demo3;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements OnCheckedChangeListener{
private ToggleButton tb;
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tb=(ToggleButton)findViewById(R.id.toggleButton1);
img=(ImageView)findViewById(R.id.imageView1);
tb.setOnCheckedChangeListener(this);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
img.setBackgroundResource(isChecked?R.drawable.on:R.drawable.of);
}

}
Logcat
05:42:29.792: E/OpenGLRenderer(1694): Getting MAX_TEXTURE_SIZE from GradienCache
11-14 05:42:29.820: E/OpenGLRenderer(1694): Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
11-14 05:42:32.596: E/dalvikvm(287): JIT code cache full
11-14 05:44:08.752: E/dalvikvm-heap(1694): Out of memory on a 71663628-byte allocation.
11-14 05:44:08.836: E/AndroidRuntime(1694): FATAL EXCEPTION: main
11-14 05:44:08.836: E/AndroidRuntime(1694): java.lang.OutOfMemoryError
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:503)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:356)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:800)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.content.res.Resources.loadDrawable(Resources.java:2105)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.content.res.Resources.getDrawable(Resources.java:695)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.view.View.setBackgroundResource(View.java:14758)
11-14 05:44:08.836: E/AndroidRuntime(1694): at com.example.demo3.MainActivity.onCheckedChanged(MainActivity.java:35)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.widget.CompoundButton.setChecked(CompoundButton.java:126)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.widget.ToggleButton.setChecked(ToggleButton.java:73)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.widget.CompoundButton.toggle(CompoundButton.java:87)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.widget.CompoundButton.performClick(CompoundButton.java:99)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.view.View$PerformClick.run(View.java:17721)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.os.Handler.handleCallback(Handler.java:730)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.os.Handler.dispatchMessage(Handler.java:92)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.os.Looper.loop(Looper.java:137)
11-14 05:44:08.836: E/AndroidRuntime(1694): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-14 05:44:08.836: E/AndroidRuntime(1694): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 05:44:08.836: E/AndroidRuntime(1694): at java.lang.reflect.Method.invoke(Method.java:525)
11-14 05:44:08.836: E/AndroidRuntime(1694): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-14 05:44:08.836: E/AndroidRuntime(1694): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-14 05:44:08.836: E/AndroidRuntime(1694): at dalvik.system.NativeStart.main(Native Method)
11-14 05:49:10.052: E/InputDispatcher(287): channel '52998960 com.example.demo3/com.example.demo3.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

...全文
366 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
摘星猿 2016-02-06
  • 打赏
  • 举报
回复
内存溢出了 图片应该是 超级大的那种 几兆么?
丑旦 2016-02-05
  • 打赏
  • 举报
回复
11-14 05:44:08.836: E/AndroidRuntime(1694): java.lang.OutOfMemoryError
lixj2001 2015-11-16
  • 打赏
  • 举报
回复
估计是图片太大的问题~
honglei92 2015-11-16
  • 打赏
  • 举报
回复
内存溢出 图片过大
Perfect411_111 2015-11-16
  • 打赏
  • 举报
回复
加载图片太大,分批加载比较好
sanxiaochengyu 2015-11-15
  • 打赏
  • 举报
回复
看起来是没有问题的,报错是OOM,图片是很大吗?换两个小点的图片看看

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧