Search code examples
androidchronometer

Cannot cast from View to Chronometer


I did everything right, I guess? I saved the xml file, but have no idea how to solve this. I'm a newbie, pls help.

Here's my xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
<Chronometer
 android:id="@+id/my_chronometer"
 android:layout_gravity="center_horizontal"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
 />
<Button
 android:id="@+id/buttonstart"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Start"
 />
<Button
 android:id="@+id/buttonstop"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Stop"
 />
<Button
 android:id="@+id/buttonreset"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="Reset"
 />
</LinearLayout>

chronometer.java:


Solution

  • The problem is with your class name I think. It has the same name as "Chronometer". This might be the cause for it. Try to replace the Activity name to something else. Maybe "chronometer" with small letter "c".