简体   繁体   English

Android-App未在真实设备上运行

[英]Android-App not running on Real Device

I've just started coding in Android,below shown is Simple calculator with basic operations,when i run it on my SONY ERICSSON LIVE WITH WALKMAN,i recieve message as "Unfortunately CACULATOR has stopped" Below shown is Console output: 我刚刚开始在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 }

Here is LogCat window message: 这是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

Sorry if i'm not able to identify simple errors..! 抱歉,如果我无法识别简单错误。

Here is my activity_main.xml 这是我的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>

What is this: android:background="@style/AppTheme" ? 这是什么:android:background =“ @ style / AppTheme”? This is the problem. 这就是问题。

You cant set Theme as a background. 您不能将主题设置为背景。 It should be color or drawable. 它应该是彩色的或可绘制的。

I haven't programmed in Android before but I have experience in JAVA. 我以前没有用Android编程,但是我有JAVA的经验。 To me, it seems you are using a resource that cannot be drawn onto the UI of the device. 对我来说,您似乎正在使用无法绘制到设备UI上的资源。

This right here seems to be the problem: 这似乎是问题所在:

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}

Check the XML again for a misplaced resource or maybe a syntax error. 再次检查XML,以查找错误放置的资源或语法错误。 If you are still getting an error, post your XML file here. 如果仍然出现错误,请在此处发布XML文件。

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM