当我单击按钮时,应用程序强制关闭。我的 java、xml 和 manifest 没有错误。我不明白为什么单击按钮时应用程序可能会强制关闭。这是java代码。
package com.aza.geopi;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.Button;
import android.view.View;
public class MenuActivity extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
Button materi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
materi = (Button)findViewById(R.id.button1);
materi.setOnClickListener(this);
}
public void onClick(View view){
if (view==materi) {
Intent intent = new Intent (MenuActivity.this, materi.class);
startActivityForResult (intent, 0);
}
}
}
这是xml代码
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/AbsoluteLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mainmenu"
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=".MenuActivity" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="210dp"
android:layout_height="68dp"
android:layout_x="80dp"
android:layout_y="160dp"
android:background="@android:color/transparent"
android:text="" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="210dp"
android:layout_height="68dp"
android:layout_x="88dp"
android:layout_y="256dp"
android:background="@android:color/transparent"
android:text="" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="210dp"
android:layout_height="68dp"
android:layout_x="80dp"
android:layout_y="355dp"
android:background="@android:color/transparent"
android:text="" />
第二课
package com.aza.geopi;
import android.app.Activity;
import android.os.Bundle;
public class materi extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.materi);
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aza.geopi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.aza.geopi.MenuActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="materi">
</activity>
</application>
日志猫
> 05-15 08:59:55.977: D/dalvikvm(272): GC_EXTERNAL_ALLOC freed 745 > objects / 54592 bytes in 76ms > 05-15 09:00:04.106: E/dalvikvm-heap(272): 18933750-byte external allocation too large for this process. > 05-15 09:00:04.106: E/GraphicsJNI(272): VM won't let us allocate 18933750 bytes > 05-15 09:00:04.126: D/AndroidRuntime(272): Shutting down VM > 05-15 09:00:04.126: W/dalvikvm(272): threadid=1: thread exiting with uncaught exception (group=0x4001d800) > 05-15 09:00:04.196: E/AndroidRuntime(272): FATAL EXCEPTION: main > 05-15 09:00:04.196: E/AndroidRuntime(272): java.lang.RuntimeException: Unable to start activity > ComponentInfo{com.aza.geopi/com.aza.geopi.materi}: > android.view.InflateException: Binary XML file line #2: Error > inflating class <unknown> > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.ActivityThread.access$2300(ActivityThread.java:125) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.os.Handler.dispatchMessage(Handler.java:99) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.os.Looper.loop(Looper.java:123) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.ActivityThread.main(ActivityThread.java:4627) > 05-15 09:00:04.196: E/AndroidRuntime(272): at java.lang.reflect.Method.invokeNative(Native Method) > 05-15 09:00:04.196: E/AndroidRuntime(272): at java.lang.reflect.Method.invoke(Method.java:521) > 05-15 09:00:04.196: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) > 05-15 09:00:04.196: E/AndroidRuntime(272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) > 05-15 09:00:04.196: E/AndroidRuntime(272): at dalvik.system.NativeStart.main(Native Method) > 05-15 09:00:04.196: E/AndroidRuntime(272): Caused by: android.view.InflateException: Binary XML file line #2: Error > inflating class <unknown> > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.LayoutInflater.createView(LayoutInflater.java:513) > 05-15 09:00:04.196: E/AndroidRuntime(272): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.LayoutInflater.inflate(LayoutInflater.java:385) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) > 05-15 09:00:04.196: E/AndroidRuntime(272): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.Activity.setContentView(Activity.java:1647) > 05-15 09:00:04.196: E/AndroidRuntime(272): at com.aza.geopi.materi.onCreate(materi.java:11) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) > 05-15 09:00:04.196: E/AndroidRuntime(272): ... 11 more > 05-15 09:00:04.196: E/AndroidRuntime(272): Caused by: java.lang.reflect.InvocationTargetException > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:47) > 05-15 09:00:04.196: E/AndroidRuntime(272): at java.lang.reflect.Constructor.constructNative(Native Method) > 05-15 09:00:04.196: E/AndroidRuntime(272): at java.lang.reflect.Constructor.newInstance(Constructor.java:446) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.LayoutInflater.createView(LayoutInflater.java:500) > 05-15 09:00:04.196: E/AndroidRuntime(272): ... 21 more > 05-15 09:00:04.196: E/AndroidRuntime(272): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.Bitmap.nativeCreate(Native Method) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.Bitmap.createBitmap(Bitmap.java:468) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.Bitmap.createBitmap(Bitmap.java:435) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.content.res.Resources.loadDrawable(Resources.java:1709) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.View.<init>(View.java:1885) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.View.<init>(View.java:1834) > 05-15 09:00:04.196: E/AndroidRuntime(272): at android.view.ViewGroup.<init>(ViewGroup.java:285) > 05-15 09:00:04.196: E/AndroidRuntime(272): ... 25 more > 05-15 09:00:08.805: I/Process(272): Sending signal. PID: 272 SIG: 9 > 05-15 09:24:41.886: D/dalvikvm(301): GC_EXTERNAL_ALLOC freed 767 objects / 55448 bytes in 77ms > 05-15 09:25:13.296: E/dalvikvm-heap(301): 18933750-byte external allocation too large for this process. > 05-15 09:25:13.296: E/GraphicsJNI(301): VM won't let us allocate 18933750 bytes > 05-15 09:25:13.296: D/AndroidRuntime(301): Shutting down VM > 05-15 09:25:13.305: W/dalvikvm(301): threadid=1: thread exiting with uncaught exception (group=0x4001d800) > 05-15 09:25:13.336: E/AndroidRuntime(301): FATAL EXCEPTION: main > 05-15 09:25:13.336: E/AndroidRuntime(301): java.lang.RuntimeException: Unable to start activity > ComponentInfo{com.aza.geopi/com.aza.geopi.materi}: > android.view.InflateException: Binary XML file line #2: Error > inflating class <unknown> > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.ActivityThread.access$2300(ActivityThread.java:125) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.os.Handler.dispatchMessage(Handler.java:99) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.os.Looper.loop(Looper.java:123) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.ActivityThread.main(ActivityThread.java:4627) > 05-15 09:25:13.336: E/AndroidRuntime(301): at java.lang.reflect.Method.invokeNative(Native Method) > 05-15 09:25:13.336: E/AndroidRuntime(301): at java.lang.reflect.Method.invoke(Method.java:521) > 05-15 09:25:13.336: E/AndroidRuntime(301): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) > 05-15 09:25:13.336: E/AndroidRuntime(301): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) > 05-15 09:25:13.336: E/AndroidRuntime(301): at dalvik.system.NativeStart.main(Native Method) > 05-15 09:25:13.336: E/AndroidRuntime(301): Caused by: android.view.InflateException: Binary XML file line #2: Error > inflating class <unknown> > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.LayoutInflater.createView(LayoutInflater.java:513) > 05-15 09:25:13.336: E/AndroidRuntime(301): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.LayoutInflater.inflate(LayoutInflater.java:385) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) > 05-15 09:25:13.336: E/AndroidRuntime(301): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.Activity.setContentView(Activity.java:1647) > 05-15 09:25:13.336: E/AndroidRuntime(301): at com.aza.geopi.materi.onCreate(materi.java:11) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) > 05-15 09:25:13.336: E/AndroidRuntime(301): ... 11 more > 05-15 09:25:13.336: E/AndroidRuntime(301): Caused by: java.lang.reflect.InvocationTargetException > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:47) > 05-15 09:25:13.336: E/AndroidRuntime(301): at java.lang.reflect.Constructor.constructNative(Native Method) > 05-15 09:25:13.336: E/AndroidRuntime(301): at java.lang.reflect.Constructor.newInstance(Constructor.java:446) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.LayoutInflater.createView(LayoutInflater.java:500) > 05-15 09:25:13.336: E/AndroidRuntime(301): ... 21 more > 05-15 09:25:13.336: E/AndroidRuntime(301): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.Bitmap.nativeCreate(Native Method) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.Bitmap.createBitmap(Bitmap.java:468) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.Bitmap.createBitmap(Bitmap.java:435) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.content.res.Resources.loadDrawable(Resources.java:1709) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.View.<init>(View.java:1885) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.View.<init>(View.java:1834) > 05-15 09:25:13.336: E/AndroidRuntime(301): at android.view.ViewGroup.<init>(ViewGroup.java:285) > 05-15 09:25:13.336: E/AndroidRuntime(301): ... 25 more > 05-15 09:25:15.475: I/Process(301): Sending signal. PID: 301 SIG: 9 > 05-15 09:41:23.535: D/dalvikvm(330): GC_EXTERNAL_ALLOC freed 789 objects / 56304 bytes in 83ms > 05-15 09:41:30.596: E/dalvikvm-heap(330): 18933750-byte external allocation too large for this process. > 05-15 09:41:30.596: E/GraphicsJNI(330): VM won't let us allocate 18933750 bytes > 05-15 09:41:30.606: D/AndroidRuntime(330): Shutting down VM > 05-15 09:41:30.606: W/dalvikvm(330): threadid=1: thread exiting with uncaught exception (group=0x4001d800) > 05-15 09:41:30.646: E/AndroidRuntime(330): FATAL EXCEPTION: main > 05-15 09:41:30.646: E/AndroidRuntime(330): java.lang.RuntimeException: Unable to start activity > ComponentInfo{com.aza.geopi/com.aza.geopi.materi}: > android.view.InflateException: Binary XML file line #2: Error > inflating class <unknown> > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.ActivityThread.access$2300(ActivityThread.java:125) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.os.Handler.dispatchMessage(Handler.java:99) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.os.Looper.loop(Looper.java:123) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.ActivityThread.main(ActivityThread.java:4627) > 05-15 09:41:30.646: E/AndroidRuntime(330): at java.lang.reflect.Method.invokeNative(Native Method) > 05-15 09:41:30.646: E/AndroidRuntime(330): at java.lang.reflect.Method.invoke(Method.java:521) > 05-15 09:41:30.646: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) > 05-15 09:41:30.646: E/AndroidRuntime(330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) > 05-15 09:41:30.646: E/AndroidRuntime(330): at dalvik.system.NativeStart.main(Native Method) > 05-15 09:41:30.646: E/AndroidRuntime(330): Caused by: android.view.InflateException: Binary XML file line #2: Error > inflating class <unknown> > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.LayoutInflater.createView(LayoutInflater.java:513) > 05-15 09:41:30.646: E/AndroidRuntime(330): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.LayoutInflater.inflate(LayoutInflater.java:385) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) > 05-15 09:41:30.646: E/AndroidRuntime(330): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.Activity.setContentView(Activity.java:1647) > 05-15 09:41:30.646: E/AndroidRuntime(330): at com.aza.geopi.materi.onCreate(materi.java:11) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) > 05-15 09:41:30.646: E/AndroidRuntime(330): ... 11 more > 05-15 09:41:30.646: E/AndroidRuntime(330): Caused by: java.lang.reflect.InvocationTargetException > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.widget.AbsoluteLayout.<init>(AbsoluteLayout.java:47) > 05-15 09:41:30.646: E/AndroidRuntime(330): at java.lang.reflect.Constructor.constructNative(Native Method) > 05-15 09:41:30.646: E/AndroidRuntime(330): at java.lang.reflect.Constructor.newInstance(Constructor.java:446) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.LayoutInflater.createView(LayoutInflater.java:500) > 05-15 09:41:30.646: E/AndroidRuntime(330): ... 21 more > 05-15 09:41:30.646: E/AndroidRuntime(330): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.Bitmap.nativeCreate(Native Method) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.Bitmap.createBitmap(Bitmap.java:468) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.Bitmap.createBitmap(Bitmap.java:435) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.content.res.Resources.loadDrawable(Resources.java:1709) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.content.res.TypedArray.getDrawable(TypedArray.java:601) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.View.<init>(View.java:1885) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.View.<init>(View.java:1834) > 05-15 09:41:30.646: E/AndroidRuntime(330): at android.view.ViewGroup.<init>(ViewGroup.java:285) > 05-15 09:41:30.646: E/AndroidRuntime(330): ... 25 more
谢谢之前