Android-App未在Real Device上运行

时间:2013-01-22 06:18:32

标签: java android android-emulator

我刚开始使用Android进行编码,下面显示的是带有基本操作的简单计算器,当我在我的SONY ERICSSON LIVE WITH WALKMAN上运行它时,我收到消息“不幸的是CACULATOR已停止” 下面显示的是控制台输出:

[2013-01-22 11:42:52 - calci] ------------------------------
[2013-01-22 11:42:52 - calci] Android Launch!
[2013-01-22 11:42:52 - calci] adb is running normally.
[2013-01-22 11:42:52 - calci] Performing com.example.calci.MainActivity activity launch
[2013-01-22 11:42:54 - calci] Uploading calci.apk onto device 'BX902W2BWH'
[2013-01-22 11:42:54 - calci] Installing calci.apk...
[2013-01-22 11:42:57 - calci] Success!
[2013-01-22 11:42:57 - calci] Starting activity com.example.calci.MainActivity on device BX902W2BWH
[2013-01-22 11:42:58 - calci] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.calci/.MainActivity }

这是LogCat窗口消息:

01-22 11:42:32.071: D/AndroidRuntime(4046): Shutting down VM
01-22 11:42:32.071: W/dalvikvm(4046): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
01-22 11:42:32.081: E/AndroidRuntime(4046): FATAL EXCEPTION: main
01-22 11:42:32.081: E/AndroidRuntime(4046): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calci/com.example.calci.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.os.Looper.loop(Looper.java:137)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.ActivityThread.main(ActivityThread.java:4441)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at java.lang.reflect.Method.invokeNative(Native Method)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at java.lang.reflect.Method.invoke(Method.java:511)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at dalvik.system.NativeStart.main(Native Method)
01-22 11:42:32.081: E/AndroidRuntime(4046): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.LayoutInflater.createView(LayoutInflater.java:606)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.Activity.setContentView(Activity.java:1835)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at com.example.calci.MainActivity.onCreate(MainActivity.java:21)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.Activity.performCreate(Activity.java:4465)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-22 11:42:32.081: E/AndroidRuntime(4046):     ... 11 more
01-22 11:42:32.081: E/AndroidRuntime(4046): Caused by: java.lang.reflect.InvocationTargetException
01-22 11:42:32.081: E/AndroidRuntime(4046):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.LayoutInflater.createView(LayoutInflater.java:586)
01-22 11:42:32.081: E/AndroidRuntime(4046):     ... 23 more
01-22 11:42:32.081: E/AndroidRuntime(4046): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f050001 a=-1 r=0x7f050001}
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.content.res.Resources.loadDrawable(Resources.java:1897)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.View.<init>(View.java:2804)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.View.<init>(View.java:2741)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.view.ViewGroup.<init>(ViewGroup.java:412)
01-22 11:42:32.081: E/AndroidRuntime(4046):     at android.widget.RelativeLayout.<init>(RelativeLayout.java:179)
01-22 11:42:32.081: E/AndroidRuntime(4046):     ... 26 more
01-22 11:43:03.361: D/AndroidRuntime(4197): Shutting down VM
01-22 11:43:03.361: W/dalvikvm(4197): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
01-22 11:43:03.371: E/AndroidRuntime(4197): FATAL EXCEPTION: main
01-22 11:43:03.371: E/AndroidRuntime(4197): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calci/com.example.calci.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.os.Looper.loop(Looper.java:137)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.ActivityThread.main(ActivityThread.java:4441)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at java.lang.reflect.Method.invokeNative(Native Method)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at java.lang.reflect.Method.invoke(Method.java:511)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at dalvik.system.NativeStart.main(Native Method)
01-22 11:43:03.371: E/AndroidRuntime(4197): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.LayoutInflater.createView(LayoutInflater.java:606)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.Activity.setContentView(Activity.java:1835)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at com.example.calci.MainActivity.onCreate(MainActivity.java:21)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.Activity.performCreate(Activity.java:4465)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-22 11:43:03.371: E/AndroidRuntime(4197):     ... 11 more
01-22 11:43:03.371: E/AndroidRuntime(4197): Caused by: java.lang.reflect.InvocationTargetException
01-22 11:43:03.371: E/AndroidRuntime(4197):     at java.lang.reflect.Constructor.constructNative(Native Method)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.LayoutInflater.createView(LayoutInflater.java:586)
01-22 11:43:03.371: E/AndroidRuntime(4197):     ... 23 more
01-22 11:43:03.371: E/AndroidRuntime(4197): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f050001 a=-1 r=0x7f050001}
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.content.res.Resources.loadDrawable(Resources.java:1897)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.View.<init>(View.java:2804)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.View.<init>(View.java:2741)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.view.ViewGroup.<init>(ViewGroup.java:412)
01-22 11:43:03.371: E/AndroidRuntime(4197):     at android.widget.RelativeLayout.<init>(RelativeLayout.java:179)
01-22 11:43:03.371: E/AndroidRuntime(4197):     ... 26 more

很抱歉,如果我无法识别简单的错误..!

这是我的activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@style/AppTheme"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="29dp"
        android:layout_marginTop="22dp"
        android:ems="10"
        android:hint="@string/enter_first_number"
        android:inputType="number" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignRight="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="26dp"
        android:ems="10"
        android:hint="Enter Second Number"
        android:inputType="number" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:text="SUB" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/button1"
        android:layout_marginBottom="45dp"
        android:text="MUL" />

    <Button 
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button3"
        android:layout_alignLeft="@+id/button2"
        android:text="DIV" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/editText2"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="66dp"
        android:text="ADD" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button2"
        android:layout_alignLeft="@+id/editText2"
        android:layout_alignRight="@+id/button1"
        android:layout_marginBottom="24dp"
        android:hint="RESULT"
        android:text="RESULT" />

</RelativeLayout>

3 个答案:

答案 0 :(得分:1)

这是什么:android:background =“@ style / AppTheme”? 这就是问题所在。

您无法将主题设置为背景。它应该是颜色或可绘制的。

答案 1 :(得分:0)

我以前没有在Android中编程,但我有JAVA的经验。 对我而言,您似乎正在使用无法在设备的UI上绘制的资源。

这就好像是问题所在:

01-22 11:42:32.081: E/AndroidRuntime(4046): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f050001 a=-1 r=0x7f050001}

再次检查XML是否存在放错位置的资源或语法错误。如果仍然出现错误,请在此处发布XML文件。

答案 2 :(得分:0)

不确定但我在EditText1中注意到您有android:hint="@string/enter_first_number"但在editText2中它是android:hint="Enter Second Number" - 应该是android:hint="@String/Enter Second Number"吗?