gpt4 book ai didi

android - 运行时异常、view.InflateException、reflection.InvocationTargetException 和 OutOfMemoryError

转载 作者:太空狗 更新时间:2023-10-29 13:24:58 27 4
gpt4 key购买 nike

我正在为 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(平板电脑)中,这款游戏运行流畅,没有此类异常。

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

这是我的 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>

最佳答案

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

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

关于android - 运行时异常、view.InflateException、reflection.InvocationTargetException 和 OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22509526/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com