我正在为android开发我的第一款游戏。我已经在我的Android手机(三星Galaxy S2)中运行和测试我的代码。在我的游戏的完成阶段,我添加了谷歌admob services.Once它被添加后我的游戏开始变慢。游戏在某些时候关闭了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(平板电脑)中,这款游戏运行顺畅,没有这些例外。
我想让我的游戏以同样的方式在所有设备上运行。请帮我完成我的第一场比赛。
这是我的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>
答案 0 :(得分:2)
检查此Android开发人员链接。并将图像放在适当大小的适当文件夹中。如果没有合适大小的图像,操作系统将尝试调整图像大小本身,这会导致内存不足异常。
https://developer.android.com/guide/practices/screens_support.html