我在模拟器(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>
您是否知道如何在我的设备上成功运行该应用程序?
答案 0 :(得分:0)
newView(...)
中定义的自定义列表项视图缺少android:layout_width
属性。需要始终将(以及layout_height属性)设置为fill_parent
或wrap_content
查看您在代码中夸大的xml布局文件:example.smartdialup.PhoneSpellDialer$ContactListAdapter.newView(PhoneSpellDialer.java:720)
RelativLayout
那里或者一个,如果它可能是子视图。
答案 1 :(得分:0)
二进制XML文件行#73:您必须提供layout_width属性。
表示您忘记在“活动视图”的Xml布局中添加android:layout_width="wrap_content"
。
答案 2 :(得分:0)
很奇怪你在模拟器和真实设备之间得到了“差异”,因为错误也应该发生在模拟器上。这是我在模拟器和真实设备中进行开发的原因之一,两者之间的行为差异超出了您的喜好。
XML文件行#73:您必须提供layout_width属性。
此错误非常简单,您添加到布局XML的每个元素都应该具有layout_width和layout_height,以便Android知道如何显示它们。
您尚未提供布局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>
请注意,layout_width和layout_height正在所有“XML标记”中使用,因此Android知道如何定位它们。
match_parent是其中一个值,您可以在Android开发者网站上找到您需要的值: http://developer.android.com/guide/topics/resources/layout-resource.html#layoutvalues
提示:您正在使用Eclipse进行Android开发?输入:android:layout_width =“然后按CTRL +空格键它应该自动完成;)