0

我在模拟器(版本 2.2)上运行我的 android 应用程序,它工作正常。但是,当我在我的 android 设备(4.1 版)上尝试该应用程序时,它不起作用。我在日志中收到如下错误:

12-27 16:54:22.080: E/Trace(25485): error opening trace file: No such file or directory (2)
12-27 16:54:22.845: E/AndroidRuntime(25485): FATAL EXCEPTION: main
12-27 16:54:22.845: E/AndroidRuntime(25485): java.lang.RuntimeException: Binary XML file line #73: You must supply a layout_width attribute.
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5696)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5832)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1099)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:956)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:70)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:748)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.ResourceCursorAdapter.newView(ResourceCursorAdapter.java:104)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at example.smartdialup.PhoneSpellDialer$ContactListAdapter.newView(PhoneSpellDialer.java:720)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.CursorAdapter.getView(CursorAdapter.java:246)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.AbsListView.obtainView(AbsListView.java:2457)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.ListView.makeAndAddView(ListView.java:1775)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.ListView.fillDown(ListView.java:678)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.ListView.fillFromTop(ListView.java:739)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.ListView.layoutChildren(ListView.java:1614)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.AbsListView.onLayout(AbsListView.java:2292)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.View.layout(View.java:14055)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewGroup.layout(ViewGroup.java:4602)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.View.layout(View.java:14055)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewGroup.layout(ViewGroup.java:4602)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.View.layout(View.java:14055)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewGroup.layout(ViewGroup.java:4602)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.View.layout(View.java:14055)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewGroup.layout(ViewGroup.java:4602)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.View.layout(View.java:14055)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewGroup.layout(ViewGroup.java:4602)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1990)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1811)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4470)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.Choreographer.doFrame(Choreographer.java:525)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.os.Handler.handleCallback(Handler.java:615)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.os.Handler.dispatchMessage(Handler.java:92)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.os.Looper.loop(Looper.java:137)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at android.app.ActivityThread.main(ActivityThread.java:4898)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at java.lang.reflect.Method.invokeNative(Native Method)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at java.lang.reflect.Method.invoke(Method.java:511)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
12-27 16:54:22.845: E/AndroidRuntime(25485):    at dalvik.system.NativeStart.main(Native Method)

这是我的 Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example.smartdialup"
   android:versionName="1.81" android:versionCode="14">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".PhoneSpellDialer"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait"
                  android:theme="@style/Main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.intent.action.CALL_BUTTON"/>
                <action android:name="android.intent.action.DIAL" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" /> 
            </intent-filter>
        </activity>
        <activity android:name="Preferences"></activity>
    </application>

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <!--  <uses-sdk android:minSdkVersion="3"></uses-sdk>-->
    <supports-screens
        android:anyDensity="true" />
</manifest> 

您知道如何在我的设备上成功运行该应用程序吗?

4

3 回答 3

0

您在您定义的自定义列表项视图似乎newView(...)缺少一个属性。android:layout_width需要始终设置(连同 layout_height 属性)为fill_parent或者wrap_content

查看您在代码中膨胀的 xml 布局文件:example.smartdialup.PhoneSpellDialer$ContactListAdapter.newView(PhoneSpellDialer.java:720)

一个RelativLayout那里或一个,如果它可能是子视图。

于 2012-12-27T13:32:26.577 回答
0

正如日志所说:

二进制 XML 文件第 73 行:您必须提供 layout_width 属性。

意味着您忘记 android:layout_width="wrap_content" 为 View 添加 Activity 的 Xml 布局。

于 2012-12-27T13:33:34.233 回答
0

很奇怪,您会在模拟器和真实设备之间发现“差异”,因为该错误也应该发生在您的模拟器上。这就是我在模拟器和真实设备中开发的原因之一,两者之间的行为比你喜欢的要大得多。

XML 文件第 73 行:您必须提供 layout_width 属性。

这个错误很直接,你添加到布局 XML 的每个元素都应该有一个 layout_width 和 layout_height ,所以 Android 知道如何显示它们。

您尚未提供布局 XML,因此我无法向您展示更正后的 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"
    android:background="#FFFFFF">
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>
</LinearLayout>

请注意,所有“XML 标签”中都使用了 layout_width 和 layout_height,因此 Android 知道如何定位它们。

match_parent 是值之一,您需要的值可以在 Android 开发者网站上找到:http: //developer.android.com/guide/topics/resources/layout-resource.html#layoutvalues

提示:您使用 Eclipse 进行 Android 开发?输入: android:layout_width=" 然后按 CTRL+SPACEBAR 它应该自动完成;)

于 2012-12-27T13:37:16.717 回答