我一直在研究一个Android应用程序,它一直只包含1个屏幕,我决定在我的应用程序中添加一个菜单屏幕以进一步开发它,但是一旦我添加了菜单屏幕并尝试运行它,它在开场时坠毁了。
这是我的MainMenu.java文件:
package com.finalyearproject;
import android.app.Activity;
import android.os.Bundle;
public class MainMenu extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu);
}
}
这是我的'mainmenu.xml'文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/imageButton1"
android:contentDescription="@string/app_name"
android:layout_width="wrap_content"
android:layout_height="453dp"
android:maxHeight="150dp"
android:maxWidth="150dp"
android:scaleType="fitCenter"
android:src="@drawable/guitarlogo" />
</LinearLayout>
最后我的AndroidManifest文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.finalyearproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<!-- Splash Screen Activity / Launcher -->
<activity
android:name="com.finalyearproject.MainMenu"
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="com.finalyearproject.TunerActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar">
</activity>
</application>
</manifest>
如果我只保留顶级活动并将其作为“com.finalyearproject.TunerActivity”,那就打开了。只有在我尝试添加崩溃的第二个屏幕/活动时才会这样。这可能是我想念的东西,但我到处都寻求帮助!
logcat的:
03-26 15:59:28.974: E/AndroidRuntime(23345): FATAL EXCEPTION: main
03-26 15:59:28.974: E/AndroidRuntime(23345): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.finalyearproject/com.finalyearproject.MainMenu}: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageButton
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.os.Looper.loop(Looper.java:137)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-26 15:59:28.974: E/AndroidRuntime(23345): at java.lang.reflect.Method.invokeNative(Native Method)
03-26 15:59:28.974: E/AndroidRuntime(23345): at java.lang.reflect.Method.invoke(Method.java:511)
03-26 15:59:28.974: E/AndroidRuntime(23345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-26 15:59:28.974: E/AndroidRuntime(23345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-26 15:59:28.974: E/AndroidRuntime(23345): at dalvik.system.NativeStart.main(Native Method)
03-26 15:59:28.974: E/AndroidRuntime(23345): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.widget.ImageButton
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-26 15:59:28.974: E/AndroidRuntime(23345): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-26 15:59:28.974: E/AndroidRuntime(23345): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.Activity.setContentView(Activity.java:1924)
03-26 15:59:28.974: E/AndroidRuntime(23345): at com.finalyearproject.MainMenu.onCreate(MainMenu.java:12)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.Activity.performCreate(Activity.java:5206)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-26 15:59:28.974: E/AndroidRuntime(23345): ... 11 more
03-26 15:59:28.974: E/AndroidRuntime(23345): Caused by: java.lang.reflect.InvocationTargetException
03-26 15:59:28.974: E/AndroidRuntime(23345): at java.lang.reflect.Constructor.constructNative(Native Method)
03-26 15:59:28.974: E/AndroidRuntime(23345): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-26 15:59:28.974: E/AndroidRuntime(23345): ... 24 more
03-26 15:59:28.974: E/AndroidRuntime(23345): Caused by: java.lang.OutOfMemoryError
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:476)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.content.res.Resources.loadDrawable(Resources.java:1963)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.widget.ImageView.<init>(ImageView.java:120)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.widget.ImageButton.<init>(ImageButton.java:87)
03-26 15:59:28.974: E/AndroidRuntime(23345): at android.widget.ImageButton.<init>(ImageButton.java:83)
03-26 15:59:28.974: E/AndroidRuntime(23345): ... 27 more
答案 0 :(得分:0)
logcat中的异常有点难以破译,但是当存在一组异常时,通常在Android上,最底层的是异常的根本原因。此log cat显示加载图像的OutOfMemory异常,它告诉您yoiu放在按钮上的图像太大。