安卓新人求指教,程序执行到一半就自动退出了?什么原因
为什么程序执行到一般就关闭了?
<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!