2014-03-26 30 views
1

我一直在研究一個android應用程序,它一直只包含一個屏幕,我決定向我的應用程序添加一個菜單屏幕以進一步開發它,但是一旦我添加菜單屏幕並試圖運行它,它就會在打開時崩潰。當我的Android應用程序添加第二個屏幕時,它不會打開

這是我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

你是如何切換這些活動的?你可以發佈該代碼嗎? – ksudu94

+0

崩潰如何? logcat在哪裏? – Kaediil

+0

添加LogCat文件,該應用程序剛剛出現「停止工作」與確定按鈕來解僱錯誤@Kaediil – CMagee33

回答

0

在logcat的例外是有點難以破譯,但往往在Android上時也有例外的集羣,底部一個是問題的根源。這個日誌貓顯示一個OutOfMemory異常加載圖像,它告訴你圖像yoiu放置在按鈕上太大。

相關問題