简体   繁体   English

我的Android应用程序正在模拟器上运行,但在android设备上却无法运行

[英]My Android App is working on the emulator but not on the android device

I'm running my android application on the emulator (version 2.2) and it works fine. 我在模拟器(版本2.2)上运行我的android应用程序,并且工作正常。 However, when I try the application on my android device (version 4.1) it doesn't work. 但是,当我在android设备(4.1版)上尝试该应用程序时,它不起作用。 I get errors in the log as follows: 我在日志中收到如下错误:

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)

And here is my Manifest.xml: 这是我的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> 

Do you have any idea how to run the application successfully on my device? 您是否知道如何在我的设备上成功运行该应用程序?

Your custom list item view defined in your newView(...) is missing a android:layout_width attribute it seems. newView(...)定义的自定义列表项视图似乎缺少android:layout_width属性。 Need to always be set (along with the layout_height attribute) to either fill_parent or wrap_content 需要始终(以及layout_height属性)设置为fill_parentwrap_content

Have a look at the xml layout file you are inflating in your code: example.smartdialup.PhoneSpellDialer$ContactListAdapter.newView(PhoneSpellDialer.java:720) 看一下您在代码中使用的xml布局文件: example.smartdialup.PhoneSpellDialer$ContactListAdapter.newView(PhoneSpellDialer.java:720)

A RelativLayout there or one if it's sub views probably. RelativLayout在那里,如果可能是子视图,则一个。

as log says : 如日志所述:

Binary XML file line #73: You must supply a layout_width attribute. 二进制XML文件第73行:您必须提供layout_width属性。

means you forget to add android:layout_width="wrap_content" in Xml layout of your Activity for View. 表示您忘记在View活动的Xml布局中添加android:layout_width="wrap_content"

Pretty strange you get that 'difference' between the emulator and your real device, because that error should also occur on your emulator. 奇怪的是,您在仿真器和实际设备之间得到了“差异”,因为该错误也应该在仿真器上发生。 That's one of the reasons why I develop in both the emulator and a real device, behavior between both differs more than you like. 这就是为什么我同时在模拟器和真实设备中进行开发的原因之一,两者之间的行为差​​异超出了您的期望。

XML file line #73: You must supply a layout_width attribute. XML文件第73行:您必须提供layout_width属性。

This error is quite straight forward, every element you add to the layout XML ought to have an layout_width and layout_height so Android knows how to display them. 这个错误非常简单明了,您添加到布局XML中的每个元素都应具有layout_width和layout_height,以便Android知道如何显示它们。

You haven't supplied the layout XML so I can't show you a corrected one. 您尚未提供布局XML,因此我无法向您显示更正的XML。 One example from my layout's: 我的布局中的一个示例:

<?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>

Notice the layout_width and layout_height are being used in all 'XML tags' so Android knows how to position them. 请注意,layout_width和layout_height已在所有“ XML标签”中使用,因此Android知道如何放置它们。

match_parent is one of the values, which one you need can be found on the Android-developer site: http://developer.android.com/guide/topics/resources/layout-resource.html#layoutvalues match_parent是其中一个值,您可以在Android-developer网站上找到所需的值: http : //developer.android.com/guide/topics/resources/layout-resource.html#layoutvalues

Tip: You're using Eclipse for developing with Android? 提示:您正在使用Eclipse进行Android开发吗? type in: android:layout_width=" and then press CTRL+SPACEBAR it should autocomplete ;) 输入:android:layout_width =“,然后按CTRL + SPACEBAR,它将自动完成;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的应用在模拟器上运行正常,但在Android设备上却无法正常运行 - My App is working fine on Emulator but not on android device 应用程式可在模拟器上正常运作,但无法在Android装置上运作 - App working fine on emulator but not working on android device 为什么我的应用程序在我的 android 仿真器上运行良好,但在我的真实 android 设备上运行不正常 - Why my app is working fine on my android emulator but its not working fine on my real android device Android应用程序在模拟器上工作,但不在真实设备上 - Android app working on emulator but not on real device 在模拟器上运行的android应用,但在设备上运行connectException - android app working on emulator but connectException on device Android App可在模拟器上运行,但在设备上启动时崩溃 - Android App working on Emulator but crashes at launch on device Android应用程序可在模拟器上运行,但不能在真实设备上运行,SharePreferences - Android app working on emulator but not real device, SharePreferences Android 应用程序在真实设备上崩溃但在模拟器上工作 - Android app crashing on real device but working on emulator Android:执行“ su”无法在我的设备/仿真器中运行 - Android: Execute “su” not working in my device/emulator Android应用程序未显示安装在模拟器和我的设备上 - Android app is not showing installed on emulator and my device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM