3

我正在为 android 开发我的第一个游戏。我一直在我的 android 手机(三星 Galaxy S2)中运行和测试我的代码。在游戏的最后阶段,我添加了 google admob 服务。一旦添加我的游戏开始变慢。游戏在某个时间点关闭,logcat 中列出了异常列表。这些 logcat 条目都没有让我知道我的错误来自何处以及来自哪里。

这是我的 logcat 条目,

03-19 19:53:34.638: D/AndroidRuntime(637): Shutting down VM
03-19 19:53:34.638: W/dalvikvm(637): threadid=1: thread exiting with uncaught exception (group=0x41587ba8)
03-19 19:53:34.648: E/AndroidRuntime(637): FATAL EXCEPTION: main
03-19 19:53:34.648: E/AndroidRuntime(637): Process: btdw.agilan.minesweeper, PID: 637
03-19 19:53:34.648: E/AndroidRuntime(637): java.lang.RuntimeException: Unable to start activity ComponentInfo{btdw.agilan.minesweeper/btdw.agilan.minesweeper.MenuPage}: android.view.InflateException: Binary XML file line #111: Error inflating class <unknown>
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.os.Handler.dispatchMessage(Handler.java:102)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.os.Looper.loop(Looper.java:136)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.ActivityThread.main(ActivityThread.java:5017)
03-19 19:53:34.648: E/AndroidRuntime(637):  at java.lang.reflect.Method.invokeNative(Native Method)
03-19 19:53:34.648: E/AndroidRuntime(637):  at java.lang.reflect.Method.invoke(Method.java:515)
03-19 19:53:34.648: E/AndroidRuntime(637):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-19 19:53:34.648: E/AndroidRuntime(637):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-19 19:53:34.648: E/AndroidRuntime(637):  at dalvik.system.NativeStart.main(Native Method)
03-19 19:53:34.648: E/AndroidRuntime(637): Caused by: android.view.InflateException: Binary XML file line #111: Error inflating class <unknown>
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.createView(LayoutInflater.java:620)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-19 19:53:34.648: E/AndroidRuntime(637):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:343)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.Activity.setContentView(Activity.java:1929)
03-19 19:53:34.648: E/AndroidRuntime(637):  at btdw.agilan.minesweeper.MenuPage.onCreate(MenuPage.java:80)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.Activity.performCreate(Activity.java:5231)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
03-19 19:53:34.648: E/AndroidRuntime(637):  ... 11 more
03-19 19:53:34.648: E/AndroidRuntime(637): Caused by: java.lang.reflect.InvocationTargetException
03-19 19:53:34.648: E/AndroidRuntime(637):  at java.lang.reflect.Constructor.constructNative(Native Method)
03-19 19:53:34.648: E/AndroidRuntime(637):  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.view.LayoutInflater.createView(LayoutInflater.java:594)
03-19 19:53:34.648: E/AndroidRuntime(637):  ... 23 more
03-19 19:53:34.648: E/AndroidRuntime(637): Caused by: java.lang.OutOfMemoryError
03-19 19:53:34.648: E/AndroidRuntime(637):  at java.io.BufferedInputStream.<init>(BufferedInputStream.java:96)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.gesture.GestureStore.load(GestureStore.java:281)
03-19 19:53:34.648: E/AndroidRuntime(637):  at android.gesture.GestureStore.load(GestureStore.java:275)
03-19 19:53:34.648: E/AndroidRuntime(637):  at com.google.ads.internal.k.a(SourceFile:42)
03-19 19:53:34.648: E/AndroidRuntime(637):  at com.google.ads.AdView.a(SourceFile:514)
03-19 19:53:34.648: E/AndroidRuntime(637):  at com.google.ads.AdView.a(SourceFile:370)
03-19 19:53:34.648: E/AndroidRuntime(637):  at com.google.ads.AdView.<init>(SourceFile:125)
03-19 19:53:34.648: E/AndroidRuntime(637):  ... 26 more
03-19 19:54:35.163: I/Process(637): Sending signal. PID: 637 SIG: 9

我什至找不到错误是来自 java 代码还是 xml 文件。请帮我弄清楚这一点。

注意:在我的 Toshiba at10-a(Tablet) 中,此游戏运行流畅,没有此类异常。

我希望我的游戏以相同的方式在所有设备上运行。请帮助我完成我的第一款游戏。

这是我的 XML 文件 menupage.xml,

    <?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/awesomepager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

<RelativeLayout 
    android:id="@+id/rLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/waterglass" >



    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/menublanket"
        android:orientation="vertical" >

        <Button
            android:id="@+id/bHighScores"
            android:layout_width="190dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="High Scores" />

        <Button
            android:id="@+id/bNewGame"
            android:layout_width="190dp"
            android:layout_height="wrap_content"
            android:layout_above="@+id/bHighScores"
            android:layout_centerHorizontal="true"
            android:text="New Game" />

        <Button
            android:id="@+id/bExit"
            android:layout_width="190dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/bHighScores"
            android:layout_centerHorizontal="true"
            android:text="Exit" />




    </RelativeLayout>

      <ImageView
            android:id="@+id/ivAnimatedSmiley"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@id/relativeLayout1"
            android:layout_marginBottom="60dp"
            android:layout_centerHorizontal="true"
             />

    <btdw.agilan.minesweeper.Title
        android:id="@+id/tvMinesweeperTitleOut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/relativeLayout1"
        android:layout_centerHorizontal="true"
        android:text="Minesweeper"
        android:textColor="#ff0000"
        android:textSize="30dp"
        android:textStyle="bold" />

    <btdw.agilan.minesweeper.Title
        android:id="@+id/tvMinesweeperTitleIn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/relativeLayout1"
        android:layout_centerHorizontal="true"
        android:text="Minesweeper"
        android:textColor="#ffffff"
        android:textSize="30dp"
        android:textStyle="bold"
        android:visibility="invisible" />

    <ImageButton 
        android:id="@+id/ibSettingsImage"
         android:layout_width="wrap_content"
          android:layout_height="wrap_content"
        android:background="@drawable/settings"
        android:layout_below="@id/relativeLayout1"
        android:layout_alignLeft="@id/relativeLayout1"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="10dp"
        />

   <ImageView
          android:id="@+id/ivLikeUs"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/fb"
         android:layout_alignRight="@id/relativeLayout1"
         android:layout_below="@id/relativeLayout1" 
          android:layout_marginTop="10dp"
          android:layout_marginRight="10dp"

        />


       <com.google.ads.AdView android:id="@+id/googleAd" 
         android:layout_width="wrap_content"
          android:layout_centerHorizontal="true"
         android:layout_height="wrap_content"
         ads:adUnitId="a15318aa0c2dc06"
         ads:loadAdOnCreate="true"
         ads:unLoadOnPause="true"
         android:layout_alignParentBottom="true"
         ads:adSize="BANNER"
        />
        </RelativeLayout>

</android.support.v4.view.ViewPager>
4

1 回答 1

2

检查这个 Android 开发者链接。并将图像放在适当大小的适当文件夹中。当您没有适当大小的图像时,操作系统将尝试自行调整图像大小,这会导致内存不足异常。

https://developer.android.com/guide/practices/screens_support.html

于 2014-03-19T15:33:34.793 回答