如何在 Motorola Cliq 上设置视图的背景

发布于 2024-10-31 06:06:00 字数 8921 浏览 0 评论 0原文

我为 Android 开发了一款隐藏物体游戏。在发布之前,我在各种手机上对其进行了测试,它在所有手机上都完全符合预期。

我遇到了一个奇怪的问题,似乎只与摩托罗拉 Cliq 有关。每次尝试启动时,它都会强制关闭应用程序。

在使用绝望的“注释掉所有内容”方法来追踪错误后,我发现RelativeLayout中的“android:background=”scrollb”行就是问题所在。我该如何解决这个问题?为什么它只发生在这

是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="scrollb" android:id="@+id/TableLayout01" android:paddingLeft="5mm" android:paddingRight="5mm" android:gravity = "center_horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"   android:fitsSystemWindows="true" android:orientation="vertical">

<TextView android:id="@+id/TextView06" android:text="" android:textSize = "10mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:layout_height="wrap_content"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView06" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="Play as Guest" android:textSize = "3mm" android:gravity = "center_horizontal" android:layout_width="match_parent"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView01" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView02" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView02" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView03" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView03" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView04" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView04" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView05" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>

<EditText  android:layout_centerHorizontal="true" android:gravity = "center_horizontal" android:layout_below="@id/TextView05" android:layout_height="wrap_content" android:layout_width="match_parent" android:text="" android:id="@+id/EditText01"></EditText>

<Button android:layout_centerHorizontal="true" android:layout_below="@id/EditText01" android:layout_width="wrap_content" android:text="Create Player" android:id="@+id/Button01" android:layout_height="wrap_content"></Button>
<TextView  android:layout_centerHorizontal="true" android:gravity = "center_horizontal" android:layout_below="@id/Button01" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView07" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Welcome to Hidden Treasures,\n your journey awaits"></TextView>

</RelativeLayout>

这是堆栈跟踪:*注意,我将相对布局更改为线性布局

04-08 13:39:50.646: ERROR/AndroidRuntime(781): Uncaught handler: thread main exiting due to uncaught exception
04-08 13:39:50.696: ERROR/AndroidRuntime(781): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.htf/com.htf.main}: android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.access$2000(ActivityThread.java:115)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.os.Looper.loop(Looper.java:123)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.main(ActivityThread.java:3977)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Method.invokeNative(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Method.invoke(Method.java:521)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at dalvik.system.NativeStart.main(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.createView(LayoutInflater.java:512)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.Activity.setContentView(Activity.java:1683)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.htf.main.onCreate(main.java:33)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 11 more
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: java.lang.reflect.InvocationTargetException
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.widget.LinearLayout.<init>(LinearLayout.java:92)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Constructor.constructNative(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.createView(LayoutInflater.java:499)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 21 more
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/title_bar_shadow.9.png from drawable resource ID #0x7f020068
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.Resources.loadDrawable(Resources.java:1643)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.View.<init>(View.java:1739)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.View.<init>(View.java:1688)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.ViewGroup.<init>(ViewGroup.java:271)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 25 more
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: java.io.FileNotFoundException: res/drawable/title_bar_shadow.9.png
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.AssetManager.openNonAssetNative(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.AssetManager.openNonAsset(AssetManager.java:417)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.Resources.loadDrawable(Resources.java:1636)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 29 more

I have developed a hidden object game for Android. I tested it on a variety of phones before launching it, and it works exactly intended on all of them.

I have come across a weird problem that seems to only pertain to the Motorola Cliq. It force closes the app every time it tries to start.

After using the desperate "comment everything out" method of tracking down the bug, I found that the line "android:background="scrollb" in the RelativeLayout is the problem. How do I get around this? Why does it only happen with the Cliq?

Here is my code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="scrollb" android:id="@+id/TableLayout01" android:paddingLeft="5mm" android:paddingRight="5mm" android:gravity = "center_horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"   android:fitsSystemWindows="true" android:orientation="vertical">

<TextView android:id="@+id/TextView06" android:text="" android:textSize = "10mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:layout_height="wrap_content"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView06" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="Play as Guest" android:textSize = "3mm" android:gravity = "center_horizontal" android:layout_width="match_parent"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView01" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView02" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView02" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView03" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView03" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView04" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>
<TextView android:clickable="true" android:layout_below="@id/TextView04" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView05" android:layout_height="wrap_content" android:text="" android:textSize = "3mm" android:gravity = "center_horizontal"  android:layout_width="match_parent" android:visibility="gone"></TextView>

<EditText  android:layout_centerHorizontal="true" android:gravity = "center_horizontal" android:layout_below="@id/TextView05" android:layout_height="wrap_content" android:layout_width="match_parent" android:text="" android:id="@+id/EditText01"></EditText>

<Button android:layout_centerHorizontal="true" android:layout_below="@id/EditText01" android:layout_width="wrap_content" android:text="Create Player" android:id="@+id/Button01" android:layout_height="wrap_content"></Button>
<TextView  android:layout_centerHorizontal="true" android:gravity = "center_horizontal" android:layout_below="@id/Button01" android:textColor="#8b4513" android:textStyle="italic" android:id="@+id/TextView07" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Welcome to Hidden Treasures,\n your journey awaits"></TextView>

</RelativeLayout>

Heres the stack trace: *Note, I changed the Relative layout to a Linear one

04-08 13:39:50.646: ERROR/AndroidRuntime(781): Uncaught handler: thread main exiting due to uncaught exception
04-08 13:39:50.696: ERROR/AndroidRuntime(781): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.htf/com.htf.main}: android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2297)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.access$2000(ActivityThread.java:115)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.os.Looper.loop(Looper.java:123)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.main(ActivityThread.java:3977)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Method.invokeNative(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Method.invoke(Method.java:521)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at dalvik.system.NativeStart.main(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class java.lang.reflect.Constructor
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.createView(LayoutInflater.java:512)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.Activity.setContentView(Activity.java:1683)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at com.htf.main.onCreate(main.java:33)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 11 more
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: java.lang.reflect.InvocationTargetException
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.widget.LinearLayout.<init>(LinearLayout.java:92)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Constructor.constructNative(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.LayoutInflater.createView(LayoutInflater.java:499)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 21 more
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/title_bar_shadow.9.png from drawable resource ID #0x7f020068
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.Resources.loadDrawable(Resources.java:1643)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.View.<init>(View.java:1739)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.View.<init>(View.java:1688)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.view.ViewGroup.<init>(ViewGroup.java:271)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 25 more
04-08 13:39:50.696: ERROR/AndroidRuntime(781): Caused by: java.io.FileNotFoundException: res/drawable/title_bar_shadow.9.png
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.AssetManager.openNonAssetNative(Native Method)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.AssetManager.openNonAsset(AssetManager.java:417)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     at android.content.res.Resources.loadDrawable(Resources.java:1636)
04-08 13:39:50.696: ERROR/AndroidRuntime(781):     ... 29 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人骨 2024-11-07 06:06:00

我发现了问题。 Android使用hdpi、mdpi、ldpi这三个文件夹。 Motorola cliq 尝试通过查找drawable 来访问资源。只是可绘制的,没有 hdpi、mdpi、ldpi。这当然不存在。

I found the problem. Android uses the three folders for hdpi, mdpi, ldpi. Motorola cliq tries to access the resources by looking in drawable. Just drawable, no hdpi, mdpi, ldpi. Which of course doesnt exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文