Android编程。应用程序意外停止

时间:2010-03-26 23:30:40

标签: android debugging

我刚刚为我的Android应用程序创建了一个界面原型并尝试运行它。不幸的是,我的应用程序意外停止了一个错误:

screenshot http://mobileka.freehostia.com/3.png

这是编辑的布局模式。一切看起来都像我想要的那样不应该有错误:

screenshot http://mobileka.freehostia.com/1.png

这是我的main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="top"
    android:background="@drawable/back" >
    <TextView
        android:id="@+id/score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "@string/scoreT"
        android:textColor="@string/scoreColor"
        android:gravity = "left"
        android:typeface="serif"
        android:textStyle="bold|italic"
        android:textSize="16sp"
        android:paddingLeft = "10px"
        android:paddingTop="4px"/>
    <TextView
        android:id = "@+id/scoreTxt"
        android:layout_toRightOf="@+id/score"
        android:textSize="16sp"
        android:paddingTop = "5px"
        android:paddingLeft="4px"
        android:typeface="serif"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="    0"
        android:textColor="@string/scoreTextColor"
        android:gravity = "left"/>
    <TextView
        android:id = "@+id/scoreSeparator"
        android:layout_toRightOf="@+id/scoreTxt"
        android:textSize="16sp"
        android:paddingTop = "3px"
        android:paddingLeft="4px"
        android:typeface="serif"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="|"
        android:textColor="@string/scoreColor"
        android:gravity = "left"/> 
    <TextView
        android:id = "@+id/timerTxt"
        android:layout_alignParentRight="true"
        android:textSize="16sp"
        android:paddingRight="10px"
        android:paddingTop="4px"
        android:typeface="serif"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@string/scoreTextColor"
        android:gravity = "right"
        android:text="00:00" />     
    <TextView
        android:id = "@+id/timer"
        android:layout_toLeftOf="@+id/timerTxt"
        android:textColor="@string/scoreColor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:padding = "3px"
        android:typeface="serif"
        android:textStyle="bold|italic"
        android:text="@string/timerT"
        android:gravity = "left"/>
    <TextView
        android:id = "@+id/timerSeparator"
        android:layout_toLeftOf="@+id/timer"
        android:textSize="16sp"
        android:paddingTop = "3px"
        android:paddingLeft="4px"
        android:typeface="serif"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="|"
        android:textColor="@string/scoreColor"
        android:gravity = "left"/> 
    <ImageButton 
        android:id="@+id/buttonOne"
        android:layout_below="@+id/score" 
        android:layout_marginTop="40px"
        android:layout_marginLeft="14px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:clickable="true" 
        android:src="@drawable/inactive"/>
    <ImageButton 
        android:id="@+id/buttonTwo"
        android:layout_toRightOf="@+id/buttonOne" 
        android:layout_marginTop="63px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonThree"
        android:layout_toRightOf="@+id/buttonTwo" 
        android:layout_marginTop="63px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonFour"
        android:layout_toRightOf="@+id/buttonThree" 
        android:layout_marginTop="63px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonFive"
        android:layout_below="@+id/buttonOne" 
        android:layout_marginTop="40px"
        android:layout_marginLeft="14px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" /> 
    <ImageButton 
        android:id="@+id/buttonSix"
        android:layout_toRightOf="@+id/buttonFive" 
        android:layout_marginTop="164px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonSeven"
        android:layout_toRightOf="@+id/buttonSix" 
        android:layout_marginTop="164px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonEight"
        android:layout_toRightOf="@+id/buttonSeven" 
        android:layout_marginTop="164px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonNine"
        android:layout_below="@+id/buttonEight" 
        android:layout_marginTop="40px"
        android:layout_marginLeft="14px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonTen"
        android:layout_toRightOf="@+id/buttonNine" 
        android:layout_marginTop="264px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonEleven"
        android:layout_toRightOf="@+id/buttonTen" 
        android:layout_marginTop="264px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />
    <ImageButton 
        android:id="@+id/buttonTwelve"
        android:layout_toRightOf="@+id/buttonEleven" 
        android:layout_marginTop="264px"
        android:layout_marginLeft="10px"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/inactive" />     
</RelativeLayout>

这是我的logcat错误(p.s.第12行是main.xml中的第一个TextView):


03-26 22:59:31.670: WARN/dalvikvm(185): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
03-26 22:59:31.727: ERROR/AndroidRuntime(185): Uncaught handler: thread main exiting due to uncaught exception
03-26 22:59:31.784: ERROR/AndroidRuntime(185): java.lang.RuntimeException: Unable to start activity ComponentInfo{kz.androidmarket.www.randomtest1/kz.androidmarket.www.randomtest1.randomTest1}: android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.os.Looper.loop(Looper.java:123)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.ActivityThread.main(ActivityThread.java:4363)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at java.lang.reflect.Method.invokeNative(Native Method)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at java.lang.reflect.Method.invoke(Method.java:521)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at dalvik.system.NativeStart.main(Native Method)
03-26 22:59:31.784: ERROR/AndroidRuntime(185): Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.Activity.setContentView(Activity.java:1622)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at kz.androidmarket.www.randomtest1.randomTest1.onCreate(randomTest1.java:11)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     ... 11 more
03-26 22:59:31.784: ERROR/AndroidRuntime(185): Caused by: java.lang.reflect.InvocationTargetException
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.widget.TextView.<init>(TextView.java:320)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at java.lang.reflect.Constructor.constructNative(Native Method)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     ... 22 more
03-26 22:59:31.784: ERROR/AndroidRuntime(185): Caused by: android.content.res.Resources$NotFoundException: File #ffff9900 from drawable resource ID #0x7f040002: .xml extension required
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.content.res.Resources.loadColorStateList(Resources.java:1820)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.content.res.TypedArray.getColorStateList(TypedArray.java:289)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     at android.widget.TextView.<init>(TextView.java:627)
03-26 22:59:31.784: ERROR/AndroidRuntime(185):     ... 26 more

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:8)

相关错误是:

03-26 22:59:31.784: ERROR/AndroidRuntime(185): Caused by: android.content.res.Resources$NotFoundException: File #ffff9900 from drawable resource ID #0x7f040002: .xml extension required

对应于:

android:textColor="@string/scoreColor"

textColor需要是颜色资源,而不是字符串资源。