views:

1206

answers:

2

I've just created a prototype of interface for my android app and tried to run it. Unfortunately I get an error that my app has stopped unexpectedly:

screenshot

This is layout mode of editing. Everything looks as I want so there shouldn't be errors:

screenshot

This is my main.xml code:

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

And this is my logcat errors (p.s. line #12 is the first TextView in main.xml):


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

Could anybody help me?

+1  A: 

The relevant error is:

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

which corresponds to:

android:textColor="@string/scoreColor"

textColor needs to be a color resource, not a string resource.

CommonsWare
Thank you very much! Everything works now! I thought that there's no difference where to get information from.
Armen Markossyan
A: 

I have the same problem: "Sorry! the application has stopped unexpectedly. Please try again." No error message is logged to the console, and the debugger doesn't stop where the error is. Anyone else notice this problem? Is there any way to find what the error message is? The debugger works fine, stepping through and setting breakpoints does work.

The application has an activity that is run when the app starts up, and also when a certain protocol is opened in the browser. Clicking the app's icon starts it fine, but starting from the browser causes the crash.

This is the activity:

package test.test;

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class testactivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);

    }

    public void onResume() {
     super.onResume();
        Uri uri = this.getIntent().getData();
        if(uri != null) {
         System.out.println(uri.toString());
        }
    }
}
anonymous
I found the errors - they are not in the console, they are in "LogCat" window. Too bad there isn't a way to copy the errors or scroll to the right...
anonymous